Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jackson as Jersey client serializer

Tags:

jackson

jersey

Is it possible to use Jackson as the serializer/marshaller for JSON data instead of JAXB when using Jersey Client API?

If so how to configure it?

like image 958
Maciej Biłas Avatar asked Mar 21 '10 18:03

Maciej Biłas


People also ask

Does Jersey use Jackson?

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

Does JAX-RS use Jackson?

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

How do I get JSON request in Jersey?

if you want your json as an Vote object then simple use @RequestBody Vote body in your mathod argument , Spring will automatically convert your Json in Vote Object.

What is Jackson JAX-RS JSON provider?

Jackson-based JAX-RS provider that can automatically serialize and deserialize resources for JSON content type (MediaType). com.fasterxml.jackson.jaxrs.json.annotation. Package that contains annotations specific to JSON dataformat.


2 Answers

OK, I found it out, it turns out to be quite simple after all:

ClientConfig cc = new DefaultClientConfig(); cc.getClasses().add(JacksonJsonProvider.class); Client clientWithJacksonSerializer = Client.create(cc); 

The JacksonJsonProvider comes from the jackson-jaxrs package.

like image 54
Maciej Biłas Avatar answered Oct 10 '22 09:10

Maciej Biłas


You may skip the creation of external config and register the provider directly:

Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class) 
like image 27
swist Avatar answered Oct 10 '22 09:10

swist