How do I use the Jersey JSON POJO support?
This did it for me - Jersey 2.3.1
In the web.xml file :
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value><my webapp packages>;org.codehaus.jackson.jaxrs</param-value>
</init-param>
</servlet>
In the pom.xml file :
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.3.1</version>
</dependency>
You can use @XmlRootElement
if you want to use JAXB annotations (see other answers).
However, if you prefer pure POJO mapping, you must do the following (Unfortunately it isn't written in docs):
- Add jackson*.jar to your classpath (As stated by @Vitali Bichov);
- In web.xml, if you're using
com.sun.jersey.config.property.packages
init parameter, addorg.codehaus.jackson.jaxrs
to the list. This will include JSON providers in the scan list of Jersey.