Jersey + Json media type application/json was not found

前端 未结 15 1012
轻奢々
轻奢々 2020-12-06 01:03

I am trying with simple Jersey + JSON example but I get following error message body writer for Java class com.test.jsonexample and MIME media type application/json w

相关标签:
15条回答
  • 2020-12-06 01:48

    I too have same issue with 1.19.4 jersey. It got fixed by adding

    compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: '2.10.0.pr1'
    

    to gradle dependency.

    Thanks, Praveen R.

    0 讨论(0)
  • 2020-12-06 01:50

    If you are not tied to jackson you could try Genson library http://owlike.github.io/genson/. You only need the lib in your classpath and every thing should work without any additional code. You wont even have to use POJOMappingFeature in web.xml nor add @XMLRootElement on your pojo!

    You can also inject instances of Genson with specific configurations using jersey mechanisms (ContextResolver).

    0 讨论(0)
  • 2020-12-06 01:53

    I know this is an old question, but I came across this issues and tried all the above solutions, but unfortunately, none of them helped me. What I found was, that the class MediaType was defined in two different jars, and when building the jar, it took the class that was defined in the other class (in my case, glassfish jar). After removing the other jar (you can also exclude the specific part), the problem was solved

    0 讨论(0)
提交回复
热议问题