Jersey Json and Pojo
I'm adding this as my own answer because i think this will help anyone with a horrible working copy of Jersey in the future. At the same time, the answer of @Michal Gajdos was grealy helpful and you should also relate to his text when having problems in the future.
What eventually helped me was a dependecy which includes pretty much every thing you need. simply add it and give it a try
<dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>2.2.3</version></dependency>
source: Git
Dependencies
Remove both jersey-media-json
(this module doesn't exist any more in Jersey 2.x) and jersey-json
(which is only for Jersey 1.x) and add one of the modules jersey-media-moxy
(JAXB) or jersey-media-json-jackson
(POJO). See JSON chapter in Jersey User Guide for more information on these modules.
web.xml
Remove com.sun.jersey.config.property.packages
and com.sun.jersey.api.json.POJOMappingFeature
which are Jersey 1.x specific and have no use in Jersey 2.x. The first one has been replaced with jersey.config.server.provider.packages
and the second one has been removed (to use POJO JSON<->Object mapping use Jackson module jersey-media-json-jackson
).
Register features
If you're using jersey-media-json-jackson
module you need to register JacksonFeature in an extension of JAX-RS application or in web.xml
(using properties from ServerProperties) - see Jackson chapter. MOXy (jersey-media-moxy
) is registered automatically when the module is on the class-path.
Enable JacksonFeature within web.xml. See also ServerProperties
<servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.your.packages</param-value> </init-param> <init-param> <param-name>jersey.config.server.provider.classnames</param-name> <param-value>org.glassfish.jersey.jackson.JacksonFeature</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>