Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we use jersey-media-json-jackson or jackson-jaxrs-json-provider in Jersey 2.5.1?

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,

like image 287
duahau Avatar asked Feb 20 '14 07:02

duahau


People also ask

Does Jaxrs use Jackson?

Open Liberty's JAX-RS 2.0 implementation uses Jackson as its default JSON provider.

Does Jersey use Jackson?

Jersey uses Jackson internally to convert Java objects to JSON and vice versa.

How do I get JSON request in Jersey?

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 .


1 Answers

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.

like image 188
ingenious Avatar answered Oct 18 '22 18:10

ingenious