You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by felixsch <f....@web.de> on 2009/03/25 10:47:47 UTC

Multiple collections in JSON Dto mixed up

Hi,

I'm using cxf 2.2 to provide a REST Service which produces XML and JSON. I
have a Dto which contains two String fields and two fields of type
Vector<String>.
What happens is, that all fields, that are declared after the first vector,
are returned as elements of this vector.

Example:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Someclass {
    String str1 = "str1";
    Vector<String> vec1 = new Vector<String>(); // contains elements
"vec1elem1" and "vec1elem2"
    String str2 = "str2";
    Vector<String> vec2 = new Vector<String>(); // contains elements
"vec2elem1" and "vec2leme2"
}

If I use XML as return value everything works fine. But JSON looks something
like this:
{"Someclass":{"str1":"str1","vec1":["vec1elem1","vec1elem2","str2","vec2elem1","vec2elem2"]}}

All following fields and all elements of following vectors are added to the
first vector.

What I tried was to set the AccessorType to NONE and add a @XmlElement
annotation to each field - this didn't change anything.

What works, is to add a @XmlList annotation to each vector. Then the fields
are interpreted correctly, but I don't really like the XmlList
representation.

Is there any way to fix this?

Thanks for your help,
Felix

-- 
View this message in context: http://www.nabble.com/Multiple-collections-in-JSON-Dto-mixed-up-tp22698194p22698194.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Multiple collections in JSON Dto mixed up

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

Sorry for a delay.
I'm wondering would using JSON object annotations solve this problem. Jettison ships them too so perhaps we could've updated 
jettison to check if JSONObjects and if they're there then use them to serialize. It's on the map anyway - I didn't get the time yet 
to do it.
Gary T - if you read it, do you think JSONObjects can help here ? If they do then the intermediate solution would be to temporarily 
create a custom provider on top of the one we ship, until we commit the fix to the trunk.

cheers, Sergey



>
> Hi,
>
> I'm using cxf 2.2 to provide a REST Service which produces XML and JSON. I
> have a Dto which contains two String fields and two fields of type
> Vector<String>.
> What happens is, that all fields, that are declared after the first vector,
> are returned as elements of this vector.
>
> Example:
>
> @XmlRootElement
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Someclass {
>    String str1 = "str1";
>    Vector<String> vec1 = new Vector<String>(); // contains elements
> "vec1elem1" and "vec1elem2"
>    String str2 = "str2";
>    Vector<String> vec2 = new Vector<String>(); // contains elements
> "vec2elem1" and "vec2leme2"
> }
>
> If I use XML as return value everything works fine. But JSON looks something
> like this:
> {"Someclass":{"str1":"str1","vec1":["vec1elem1","vec1elem2","str2","vec2elem1","vec2elem2"]}}
>
> All following fields and all elements of following vectors are added to the
> first vector.
>
> What I tried was to set the AccessorType to NONE and add a @XmlElement
> annotation to each field - this didn't change anything.
>
> What works, is to add a @XmlList annotation to each vector. Then the fields
> are interpreted correctly, but I don't really like the XmlList
> representation.
>
> Is there any way to fix this?
>
> Thanks for your help,
> Felix
>
> -- 
> View this message in context: http://www.nabble.com/Multiple-collections-in-JSON-Dto-mixed-up-tp22698194p22698194.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


Re: Multiple collections in JSON Dto mixed up

Posted by Daniel Kulp <dk...@apache.org>.
On Tue April 14 2009 10:56:04 am felixsch wrote:
> Just FYI: this jettison bug was fixed in the latest jettison 1.1-SNAPSHOT
> version--everything works for me now.

Cool.  Thanks for verifying that.   I'm working with Dejan to get a couple 
fixes in place and a 1.1 out later this week for use with 2.2.1.  Hopefully 
he'll get that done so 2.2.1 can work better "out of the box".


Dan


>
> Regards,
> Felix
>
> felixsch wrote:
> > Hi,
> >
> > thank you both for your replies.
> >
> > Dan, I followed your suggestion, turns out this is a jettison bug. I
> > could reproduce it just using a JAXBContext and a jettison
> > MappedXMLStreamWriter.
> >
> > Looks like this bug was already reported at jettison for a few month ago
> > (http://jira.codehaus.org/browse/JETTISON-48), but the fix wasn't merged
> > in the jettison source. I tried the newest snapshot version, didn't work
> > either.
> > I added a comment to the bug.
> >
> > I guess for now I'll have to use the @XmlList annotation.
> >
> > Felix
> >
> > dkulp wrote:
> >> This SOUNDS like a bug in jettison.   If you could create a small sample
> >> that
> >> just uses the Jettison stream and a JAXBContext that shows this and post
> >> that
> >> into the jettison bugs:
> >> http://jira.codehaus.org/browse/JETTISON
> >> that would be best.
> >>
> >> Dan

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: Multiple collections in JSON Dto mixed up

Posted by felixsch <f....@web.de>.
Just FYI: this jettison bug was fixed in the latest jettison 1.1-SNAPSHOT
version--everything works for me now.

Regards,
Felix


felixsch wrote:
> 
> Hi,
> 
> thank you both for your replies.
> 
> Dan, I followed your suggestion, turns out this is a jettison bug. I could
> reproduce it just using a JAXBContext and a jettison
> MappedXMLStreamWriter.
> 
> Looks like this bug was already reported at jettison for a few month ago
> (http://jira.codehaus.org/browse/JETTISON-48), but the fix wasn't merged
> in the jettison source. I tried the newest snapshot version, didn't work
> either.
> I added a comment to the bug.
> 
> I guess for now I'll have to use the @XmlList annotation.
> 
> Felix
> 
> 
> dkulp wrote:
>> 
>> 
>> This SOUNDS like a bug in jettison.   If you could create a small sample
>> that 
>> just uses the Jettison stream and a JAXBContext that shows this and post
>> that 
>> into the jettison bugs:
>> http://jira.codehaus.org/browse/JETTISON
>> that would be best.
>> 
>> Dan
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Multiple-collections-in-JSON-Dto-mixed-up-tp22698194p23041106.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Multiple collections in JSON Dto mixed up

Posted by felixsch <f....@web.de>.
Hi,

thank you both for your replies.

Dan, I followed your suggestion, turns out this is a jettison bug. I could
reproduce it just using a JAXBContext and a jettison MappedXMLStreamWriter.

Looks like this bug was already reported at jettison for a few month ago
(http://jira.codehaus.org/browse/JETTISON-48), but the fix wasn't merged in
the jettison source. I tried the newest snapshot version, didn't work
either.
I added a comment to the bug.

I guess for now I'll have to use the @XmlList annotation.

Felix


dkulp wrote:
> 
> 
> This SOUNDS like a bug in jettison.   If you could create a small sample
> that 
> just uses the Jettison stream and a JAXBContext that shows this and post
> that 
> into the jettison bugs:
> http://jira.codehaus.org/browse/JETTISON
> that would be best.
> 
> Dan
> 

-- 
View this message in context: http://www.nabble.com/Multiple-collections-in-JSON-Dto-mixed-up-tp22698194p22739116.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Multiple collections in JSON Dto mixed up

Posted by Daniel Kulp <dk...@apache.org>.
This SOUNDS like a bug in jettison.   If you could create a small sample that 
just uses the Jettison stream and a JAXBContext that shows this and post that 
into the jettison bugs:
http://jira.codehaus.org/browse/JETTISON
that would be best.

Dan


On Wed March 25 2009 5:47:47 am felixsch wrote:
> Hi,
>
> I'm using cxf 2.2 to provide a REST Service which produces XML and JSON. I
> have a Dto which contains two String fields and two fields of type
> Vector<String>.
> What happens is, that all fields, that are declared after the first vector,
> are returned as elements of this vector.
>
> Example:
>
> @XmlRootElement
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Someclass {
>     String str1 = "str1";
>     Vector<String> vec1 = new Vector<String>(); // contains elements
> "vec1elem1" and "vec1elem2"
>     String str2 = "str2";
>     Vector<String> vec2 = new Vector<String>(); // contains elements
> "vec2elem1" and "vec2leme2"
> }
>
> If I use XML as return value everything works fine. But JSON looks
> something like this:
> {"Someclass":{"str1":"str1","vec1":["vec1elem1","vec1elem2","str2","vec2ele
>m1","vec2elem2"]}}
>
> All following fields and all elements of following vectors are added to the
> first vector.
>
> What I tried was to set the AccessorType to NONE and add a @XmlElement
> annotation to each field - this didn't change anything.
>
> What works, is to add a @XmlList annotation to each vector. Then the fields
> are interpreted correctly, but I don't really like the XmlList
> representation.
>
> Is there any way to fix this?
>
> Thanks for your help,
> Felix

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog