users@jersey.java.net

[Jersey] Re: Programmatically configure Jackson POJO mapping?

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Thu, 21 Feb 2013 10:10:10 +0100

Hi Noah,

if you want to use Jackson JSON providers in a Jersey 2 application you
need to register JacksonFeature in your Application.
You can take a look at json-jackson example ([1]) to see how such a
feature should be registered ([2]).

Note that in Jersey2 we currently depends on Jackson 1.9.8.

[1] https://github.com/jersey/jersey/tree/master/examples/json-jackson
[2]
https://github.com/jersey/jersey/blob/master/examples/json-jackson/src/main/java/org/glassfish/jersey/examples/jackson/MyApplication.java

thanks,
Michal

On 21.02.2013 05:42 , Noah White wrote:
> OK good to know.
>
> My simple Jersey 2 test project is failing to serialize a POJO into JSON with:
>
> MessageBodyWriter not found for media type=application/json, type=class example.Movie, genericType=class example.Movie
> Is the Jackson 2 Jax-rs provider not bundled with GF4? With GF v3.1.2.2 the provider was JacksonProviderProxy was it not? I don't see that in the GF4 distro.
>
> Thanks,
>
> -Noah
>
> On Feb 20, 2013, at 1:10 PM, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
>
>> On Wed, Feb 20, 2013 at 8:38 AM, Noah White <emailnbw_at_gmail.com> wrote:
>>> All the examples I have seen configure Jackson POJO mapping (non-JAXB) using the web.xml.
>>>
>>> Is there a way to do this programmatically?
>> Yes, ObjectMapper is registered using standard JAX-RS provider mechanism.
>> Same for Jackson JAX-RS provider. So web.xml is just one way.
>>
>> And in fact, Jackson 2.0 JAX-RS provider auto-registers, if added in classpath.
>>
>> -+ Tatu +-