Jersey 2.x does not support POJO to json?

烂漫一生 提交于 2019-11-30 21:04:02

Yeah so the Jersey distribution doesn't come with any JSON/POJO support. You need to find them yourself and add them to your project.

If you want to use the JacksonFeature, then you need to grab all the jars for it. You can specify any class you want in the provider classes param, but if you don't actually have it, nothing will happen. You are not even told by any exceptions.

These are all the jars you need

  • jersey-media-json-jackson-2.17
  • jersey-entity-filtering-2.17
  • jackson-jaxrs-json-provider-2.3.2
  • jackson-core-2.3.2
  • jackson-databind-2.3.2
  • jackson-annotations-2.3.2
  • jackson-jaxrs-base-2.3.2
  • jackson-module-jaxb-annotations-2.3.2

Note that these are all the jars that are used for Jersey 2.17. If you are using a newer version, then you should go here, and select the version of Jersey you are using. You can download it. Then search for the entity-filtering jar with the same version.

All the other Jackson jars are of the same version, but you should see which version of Jackson the jersey-media-json-jackson uses. When you click the Jersey version, you should be able to scroll down to see which Jackson version it uses. Then just start searching for all the above Jackson jars for that version.

For instance, if you select the latest Jersey 2.21 version of the jersey-media-json-jackson, you can scroll down and see that it uses Jackson 2.5.4. So you should search for all the above Jackson jars in 2.5.4 instead of the 2.3.2 as shown above.


Note for Maven users, all you need is

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>${jersey2.version}</version>
</dependency>

This dependency will pull in all the jars you see listed above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!