users@jersey.java.net

[Jersey] Re: Question about natural notation

From: NBW <emailnbw_at_gmail.com>
Date: Tue, 15 Mar 2011 22:53:42 -0400

Hi Tatu -

I'm using 1.5. So you are saying there should be no wrapping by default with
POJO support? That's what I am seeing. So for example if I have:

@XmlRootElement
public class MyEntityDTO {

    private long id;
    private String computer;
    private long operation;
    private List<AnotherEntityDTO> moreDTOs;
    ...

I get some JSON that looks like this:

{"id":7,"operation":1,"computer":"AAA", "moreDTOs":[]}

as opposed to JSON that includes the wrapped XmlRootElement like so:

{"myEntityDTO":{"id":7,"operation":1,"computer":"AAA", "moreDTOs":[]}}

So I guess from the sound of it I can't have my cake (wrapping) and POJO
support until 1.7. Is it possible to get wrapped empty arrays (like POJO
support is giving me with *"moreDTOs":[] *using JAXB natural or some other
flavor that supports wrapping?

Cheers,

-Noah


On Tue, Mar 15, 2011 at 4:30 PM, Tatu Saloranta <tsaloranta_at_gmail.com>wrote:

> On Tue, Mar 15, 2011 at 12:37 PM, NBW <emailnbw_at_gmail.com> wrote:
> > I'm experimenting with using JAXBContextResolver and I have a
> > JSONConfiguration.natural().rootUnwrapping(false) setting for my context.
> > Things look good but one thing that isn't formatting just right for my
> needs
> > is the case where a property is a List and the list has 0 elements. Right
> > now it is left out of the JSON response. What I would like is to include
> it
> > with the root element wrapped like so:
> > "fooList":[]
> > That is the behavior I am seeing with Jackson POJO support, however, I
> can't
> > find a way to turn off rootUnwrapping in general with that or I would go
> > that route. Thanks!
>
> With Jackson POJO support, there should not be wrapping by default.
> With 1.7 you can enable wrapping (but there is no support for
> unwrapping, yet). So if you see wrapper value, it is an indication
> that perhaps pojo style is not enabled?
>
> -+ Tatu +-
>