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?
Jersey uses Jackson internally to convert Java objects to JSON and vice versa.
Open Liberty's JAX-RS 2.0 implementation uses Jackson as its default JSON provider.
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.
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.
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.
You may skip the creation of external config and register the provider directly:
Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class)
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