users@jersey.java.net

[Jersey] Re: Proper Configuration of Jackson 2.0 in Jersey 2.6

From: <tommif_at_iki.fi>
Date: Mon, 24 Feb 2014 21:59:47 +0200

Hopefully I'm not talking too much bull here. Let's try:

For future reference to any hapless soul trying to meddle with Jersey's
twisted magic:

The center ingredient to customizing Jackson's ObjectMapper is to make
Jersey use Jackson's own JAX-RS <-> Jackson MessageBodyReader and
MessageBodyWriter instead of it's own.
- Jackson's JAX-RS integration looks up the ObjectMapper instance from
ContextResolvers.
- Jersey-provided Jackson integration doesn't, and instead instantiates
it's own, leaving no room for customizing the ObjectMapper.

Step 1. Implement ContextResolver<ObjectMapper> to provide your
customized ObjectMapper instance and register it with Jersey.
Step 2. Register
com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider with Jersey.
Step 3. Done.


On 24.2.2014 19:16, Robert DiFalco wrote:
> I'm not really clear on the correct path to do this in 2.6. I had to
> go through a lot in 2.5x. Am I to understand that I know longer use
> JacksonFeature? That I only need to declare a ContextResolver for my
> ObjectMapper instance? If so this doesn't seem to be working for me.
> Maybe I need to register the my ContextResolver explicitly (not just
> annotated with Provider)? Or maybe I'm missing a dependency? I assumed
> I could now exclude media jackson json.
>
> The Jersey documentation is not up to date on this matter and still
> seems to be advising on the method used in 2.5 to configure Jackson 1.x.
>
> TIA