> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Monday, November 04, 2013 2:20 PM
> To: KARR, DAVID
> Cc: [email protected]
> Subject: Re: Configure json to give array of foo objects instead of array of
> objects with key of "foo" and value of foo object?
> 
> Hi David
> 
> Sure. Suppose you need to have only
> 
> "[...]", i.e, we have a pure array going out, with no "{" and "}".
> 
> This can be done like this:
> JSONProvider<Book> provider = new JSONProvider<Book>();
> provider.setSerializeAsArray(true);
> provider.setDropRootElement(true);
> provider.setDropElementsInXmlStream(false);
> 
> Typically dropping the elements is done at CXF (XMLStreamWriter) level,
> but this can confuse Jettison when dealing with arrays is also needed.
> So the last code line ensures it is done at Jettison level.
> 
> You can also do
> 
> JSONProvider<ReportDefinition> provider
>              = new JSONProvider<ReportDefinition>();
> provider.setSerializeAsArray(true);
> provider.setArrayKeys(Collections.singletonList("reportDefinition"));
> provider.setOutDropElements(Collections.singletonList("reportDefinition"));
> provider.setDropElementsInXmlStream(false);
> 
> That can affect the arbitrary elements.
> 
> Ask your team to give us a bean not resembling the one used in the
> production, get them create a bean named Foo, with the list field like
> "List<Bar> bars", etc :-), so that we can experiment

Ok, let's say my "ConfigInfo" class has the following:

    @XmlElementWrapper(name = "devices")
    @XmlElement(name = "device")
    private List<Device>    devices;

I've created an instance that only has one element in the devices list.  What I 
want to see is the following:

{"configInfo":{"devices":[{"name":"abc","type":"def"}]}}

What I'm currently getting is the following:

{"configInfo":{"devices":[{"device":{"name":"abc","type":"def"}}]}}

I'm first trying to get this working in an integration test, using the 
JAXRSServerFactoryBean class, so I'll definitely be manually creating my 
JSONProvider objects.

I've tried various things based on what you said, but it's not made a 
difference as of yet.

> On 04/11/13 20:44, KARR, DAVID wrote:
> >> -----Original Message-----
> >> From: Sergey Beryozkin [mailto:[email protected]]
> >> Sent: Friday, November 01, 2013 3:39 AM
> >> To: [email protected]; KARR, DAVID
> >> Subject: Re: Configure json to give array of foo objects instead of array
> of
> >> objects with key of "foo" and value of foo object?
> >>
> >> Hi David,
> >> On 31/10/13 23:30, KARR, DAVID wrote:
> >>> I'm working with some people who had some trouble configuring both xml
> and
> >> json output in Jersey, and I wanted to see how their particular problem
> could
> >> be resolved in CXF.  I haven't had to deal with the particular problem
> they
> >> had, and a quick search of the docs didn't give me an answer.
> >>>
> >>> In short, they were hoping to get a json structure like the following:
> >>>
> >>> {..., [{"prop1": prop1, "prop2": prop2},...], ...}
> >>>
> >>> Where the objects in the array are "Foo" objects.
> >>>
> >>> What they got was this:
> >>>
> >>> {..., [{"foo": {"prop1": prop1, "prop2": prop2}},...], ...}
> >>>
> >>> So instead of the "Foo" object, they got a wrapper object whose key is
> >> "foo", and the value is the "Foo" object.  Is it practical to configure
> >> Jettison in CXF to do this?
> >>>
> >> I need to see a sample JAXB bean and experiment with it, there are quite
> >> a few ways to affect the Jettison output now, but I'd like to see how
> >> the actual bean.
> >>
> >> It is possible now to do only say
> >> "[{"prop1": prop1, "prop2": prop2},...]"
> >>
> >> but I'm not sure if having such an array alongside other sibling
> >> properties is possible yet
> >
> > I'm still waiting for more detail from them on the detailed issues they
> were seeing, but in the meantime can you give me some hints on how I make
> these kinds of changes, without knowing exactly what we're going to be doing
> yet?
> >

Reply via email to