[Jersey] Re: Customizing ObjectMapper

From: Gili <>
Date: Sat, 2 Apr 2011 21:33:34 -0700 (PDT)

Gili wrote:
> Hi,
> I'd like to register a Jackson deserializer for a 3rd-party class I cannot
> annotate. I believe the only way to do this is by customizing the
> ObjectMapper that Jackson uses. I tried injecting my own ObjectMapper
> instance using Guice but it looks like
> com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy instantiates
> ObjectMapper directly.
> How am I supposed to register custom (de)serializers for 3rd-party
> classes?
> Thank you,
> Gili

Answering my own question. On the server side, all you need to do is
register a ContextResolve as a JAX-RS provider and JacksonProviderProxy will
use it:

public class ObjectMapperProvider implements ContextResolver
        public ObjectMapper getContext(Class<?> type)
                final ObjectMapper result = new ObjectMapper();
                SimpleModule module = new SimpleModule(getClass().getName(), new
Version(1, 0, 0, null)).
                        addDeserializer(PhoneNumber.class, new
                        PhoneNumber.class, new PhoneNumberSerializer());
                return result;

On the client side you need to register the provider as follows:



View this message in context:
Sent from the Jersey mailing list archive at