According to jersey spec, we can use jersey-media-json-jackson to serialize/deserialize json/pojo, however from some thread in StackOverflow, we can use also jackson-jaxrs-json-provider 2.2.3
Can you please advise which one we should use?
Thanks,
Open Liberty's JAX-RS 2.0 implementation uses Jackson as its default JSON provider.
Jersey uses Jackson internally to convert Java objects to JSON and vice versa.
Jersey endpoints and return a JSON responseGET /json/ , returns a JSON string. GET /json/{name} , returns an User object containg the {name} in JSON string. GET /json/all , returns a list of User objects in JSON string. POST /json/create , accepts JSON data and returns a status 201 .
The right way to do it is to use something like this in your maven configuration (if you are using maven, of course):
...
<properties>
<jersey.version>2.5.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
...
TL;DR - you should use jersey-media-json-jackson 2.5.1
Using the jackson library directly might break some of the auto-discoverable features of jersey.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With