Jersey-Json dependency : error on ConversionServiceAwareObjectMapper.java
I am deploying Jersey in Spring-MVC and trying to produce json output format. I have this annotation @Produces("application/json")
in MyResource.java. First, I got an error:
SEVERE: A message body writer for Java class edu.ucdavis.iet.APerson, and Java type class edu.ucdavis.iet.APerson, and MIME media type application/json was not found
I added jersey-json dependency to pom.xml:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.5</version>
</dependency>
The error is gone, but it marks anoth开发者_Python百科er error on: src/main/java/org/springframework/samples/mvc/ajax/json/ConversionServiceAwareObjectMapper.java. The errors are :
The type org.codeHaus.jackson. Versioned cannot be resolved. It is indirectly referenced from required .class file
The hierarchy of the type ConversionServiceAwareObjectMapper.java. is inconsistent.
I have searched many docs and tried to modify the configure files, but none is working. Any suggestion?
Thanks
Check if you have annotated edu.ucdavis.iet.APerson with JAXBXmlElement or JAXBXmlRootElement. If yes, you could try to use 'text/xml' instead of 'application/json' to see if it works.
You need to add Jackon Json Mapper to your dependencies. ConversionServiceAwareObjectMapper probably extends ObjectMapper which is a class in the Jackson jar.
I found out the solution. I added following contents to pom.xlm. The JSON works fine using CURL on the command-line.
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-lgpl</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.6.4</version>
</dependency>
精彩评论