In this tutorial" I will show you how to resolve problem with: MessageBodyWriter not found for media type=application/json. It could be due to missing jersey-media-json-jackson dependency.
Table of Contents
Problem
The error MessageBodyWriter not found for media type=application/json
typically indicates that there is a problem with the way you are trying to serialize or deserialize data in your application.
This error can occur if you are using a Java" application that is trying to send or receive data in JSON" format, but the necessary libraries or dependencies are not available. It may also occur if you are trying to use a JSON" library that is not compatible with your application.
To resolve this error, you may need to include the necessary libraries or dependencies in your application, or switch to a different JSON" library that is compatible with your application. You may also need to check your application’s configuration to ensure that it is set up correctly to use JSON".
If you are using a Java application that is built with a framework like JAX-RS or Jersey, you may need to include the necessary JAX-RS or Jersey dependencies in your application to support JSON" serialization and deserialization.
Solution
To resolve the issue please add the required library to your project. Because Maven and Gradle are two the most popular build automation tools I provide the dependency entry for each one.
Maven
To add the missing dependency just go to the Maven" Repository and choose appropriate version or copy past the following code:
<dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.32</version> </dependency>
Gradle Version
When you are using Gradle" you can choose the newest Gradle version. Check the link to find the newest one. When I was writing this post it was the v7.4.2.
... compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.32' ...
Select Version From Maven Repository
Please verify which version you should add to your project. You can check the available version in Central Maven Repository.
![[SOLVED] MessageBodyWriter not found for media type=application/json - Check Simple 1 Min Solution! 2 MessageBodyWriter not found for media type=application/json](https://bigdata-etl.com/wp-content/uploads/2022/03/Zrzut-ekranu-2022-03-22-o-17.07.53.png)
How To Check Project Dependencies
Maven Dependency Tree
The Maven" Dependency Tree is a tool that is used to visualize the dependencies of a Maven" project. It shows the relationships between the different artifacts (libraries and packages) that are required to build and run the project, and it can help you understand how these artifacts are connected and how they fit together.
To view the Maven" Dependency Tree for a project, you can use the mvn dependency:tree
command. This will generate a tree-like output that shows the dependencies of the project, including the transitive dependencies (dependencies of dependencies). The output will include the group ID, artifact ID, and version of each dependency, as well as its scope (compile, test, runtime, etc.).
The Maven" Dependency Tree can be useful for troubleshooting dependency conflicts or understanding the dependencies of a project. You can also use it to identify which dependencies are being included in your project, and to determine which dependencies are necessary and which can be removed.
You can find more information about the Maven" Dependency Tree and how to use it in the Maven" documentation.
In the process of finding the missing dependency, we can use the dependency tree command:
mvn dependency:tree
The snippet from execution the above column" looks like the following code:
[INFO] com.bigdataetl.spark:jar:0.0.0-SNAPSHOT [INFO] +- net.lingala.zip4j:zip4j:jar:2.6.1:compile [INFO] +- info.batey.kafka:kafka-unit:jar:1.0:test [INFO] | +- junit:junit:jar:4.11:compile [INFO] | | \- org.hamcrest:hamcrest-core:jar:1.3:compile [INFO] | \- org.apache.zookeeper:zookeeper:jar:3.4.10:provided [INFO] +- org.apache.kafka:kafka-clients:jar:0.11.0.3:compile [INFO] | +- org.xerial.snappy:snappy-java:jar:1.1.2.6:compile [INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile [INFO] +- org.apache.kafka:kafka_2.11:jar:0.11.0.3:test [INFO] | +- net.sf.jopt-simple:jopt-simple:jar:5.0.3:test [INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:test [INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.25:provided [INFO] | \- com.101tec:zkclient:jar:0.10:test ... etc...
Summary
If we use third party libraries, we often encounter the problem of incompatibility of libraries. When we change / raise the version of one library, it may turn out that it no longer contains a built-in dependency. Then, unfortunately, we have to find the missing library and attach it ourselves.
I hope this helps! If you have any more questions or are still having trouble, please let me know and I’ll do my best to help.
Could You Please Share This Post?
I appreciate It And Thank YOU! :)
Have A Nice Day!