users@jersey.java.net

[Jersey] Re: Using Jackson for data binding with annotations

From: Julien Dreux <jdreux_at_justlexit.com>
Date: Mon, 14 May 2012 16:38:42 -0400

Answering my own question. This can be achieved by setting the following on
the JacksonJsonProvider instance:

JacksonJsonProvider jjp = new JacksonJsonProvider();

jjp.configure(Feature.WRITE_NULL_MAP_VALUES, false);

jjp.configure(Feature.WRITE_NULL_PROPERTIES, false);


A full description of my solution can be found in response to my stack
overflow question (
http://stackoverflow.com/questions/10455061/forcing-jackson-to-ignore-type-properties-for-polymorphic-types-with-jersey).
Thanks to Tatu Saloranta for all the help provided.
*
*
*JULIEN DREUX*
jdreux_at_justlexit.com
514 812-8084
www.justlexit.com


On Mon, May 14, 2012 at 4:28 PM, Julien Dreux <jdreux_at_justlexit.com> wrote:

> Tatu, you are truly a master.
>
> My only complaint now is that all my null values get outputed, see below:
>
>
> 1. {
> 2. "name": "Subway",
> 3. "deviceId": "12341234"
> 4. "details": null,
>
> *
> *
> Before I added that getSingletons line of code, they used to be omitted
> from the JSON, which is the desired behaviour.
>
> What can I do to make that work?
>
> Thanks,
>
>
> *JULIEN DREUX*
> jdreux_at_justlexit.com
> 514 812-8084
> www.justlexit.com
>
>
> On Mon, May 14, 2012 at 4:17 PM, Tatu Saloranta <tsaloranta_at_gmail.com>wrote:
>
>> On Mon, May 14, 2012 at 12:32 PM, Julien Dreux <jdreux_at_justlexit.com>
>> wrote:
>> > Here's how I am doing it. This works, I see the JSON generated, but the
>> > output is still in a bad format:
>> >
>>
>> Right. It seems to me that with this:
>>
>> > @Provider
>> >
>> > public abstract class AbstractBusinessServices extends Application
>> > implements ContextResolver<JacksonJsonProvider>,
>> >
>> > ExceptionMapper<Exception>{
>> >
>> > private JacksonJsonProvider context;
>> >
>> > private Class[] types;
>> >
>> >
>> > private Logger logger =
>> > LoggerFactory.getLogger(AbstractBusinessServices.class.getName());
>> >
>> >
>> > public AbstractBusinessServices() {
>>
>> you should just add something like:
>>
>> @Override
>> public Set<Object> getSingletons() {
>> Set<Object> s = new HashSet<Object>();
>> s.add(new JacksonJsonProvider());
>> return s;
>> }
>>
>> to add the provider, and things would work...
>>
>> -+ Tatu +-
>>
>
>