More info...

Sireesh: I've got you case fixed in the local Jettison snapshot - it proved to be very tricky to fix, given that Jettison supports all types of nested arrays or arrays with different key elements, so just trying to figure out that part was tricky :-)
The other problem is that if you look at sequences such as:

"{

"Keys":[{"RegistrationKey":"1234567abcd"}, {"RegistrationKey":"789xyz"}]
}"

(your case)

and say

"{

    "Book":[{"Name":"1"}, {"Name":"2"}]
}"


which is identical in structure,

much depends on what "Keys" and "Book" map to in JAXB bean, a collection of primitives (ex, String) or beans like "Book".

Jettison can not send the correct sequence of reader events unless it knows that "Keys" is a primitive array. Nothing needs to be done in other case, works OK. It is very similar to the issue of serializing the single-element lists where Jettison needs a hint, and the same will have to be done in case of reading primitive arrays to avoid losing the array values.

It's awkward but is reasonable enough for not so big payloads, given that Jettison (at the moment at least) does not have an introspection info...After 1.3.3 release, only in cases like yours, "primitiveArrayKeys" list property will need to be set (ex, containing a single "Keys" value).


John:

Given

String input =
            " {"
            + "\"BookResponse\":{"
            + "\"BookHeader\":["
            + "       {"
            + "\"BookHeaderDtls\":{\"name\":\"1\"}"
            + "       },"
            + "       {"
            + "\"BookHeaderDtls\":{\"name\":\"2\"}"
            + "       }"
            + "   ]"
            + " }"
            + "}";

the following works OK:

BookResponse response = new JSONProvider<BookResponse>().readFrom(BookResponse.class, null, null, null, null, new ByteArrayInputStream(input.getBytes()));
        assertNotNull(response);
        List<BookHeader> headers = response.getBookHeader();
        assertEquals("1", headers.get(0).getDetail().getName());
        assertEquals("2", headers.get(1).getDetail().getName());

where the beans look like this:

@XmlRootElement(name = "BookResponse")
    public static class BookResponse {
        private List<BookHeader> bookHeader;

        @XmlElement(name = "BookHeader")
        public List<BookHeader> getBookHeader() {
            return bookHeader;
        }

        public void setBookHeader(List<BookHeader> name) {
            this.bookHeader = name;
        }
    }

    @XmlRootElement
    public static class BookHeader {
        private BookHeaderDtls detail;

        @XmlElement(name = "BookHeaderDtls")
        public BookHeaderDtls getDetail() {
            return detail;
        }

        public void setDetail(BookHeaderDtls detail) {
            this.detail = detail;
        }
    }

    @XmlRootElement
    public static class BookHeaderDtls {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

Sergey

On 06/01/13 23:00, Sergey Beryozkin wrote:
Hi
On 20/11/12 10:46, jbright wrote:
Sergey / Sireesh

Do we have a solution for this issue?

I do have the similar problem.

The JSONProvider is not creating collection properly.

{
"BookResponse":{
"BookHeader":[
{
"BookHeaderDtls":{ .... }
}]
"BookHeader":[
{
"BookHeaderDtls":{ .... }
}]

Irrespective of creating the list with "BookHeader" and populate the
BookHeaderDtls, I get only one "BookHeader":[{ and all the BookHeaderDtls
are populated inside that.

But the schema is defined to have a list of BookHeader, which in XML
response is perfect like this

<BookResponse>
<BookHeader> ....</BookHeader>
<BookHeader> ....</BookHeader>
<BookHeader> ....</BookHeader>
<BookHeader> ....</BookHeader>
<BookHeader> ....</BookHeader>
......
</BookResponse>


How does BookResponse JAXB bean look like (what annotations are used) ?
And also BookHeaderDtls ?

By the way, should it be:

" {
"BookResponse":{
"BookHeader":[
{
"BookHeaderDtls":{ .... }
},
{
"BookHeaderDtls":{ .... }
}
]
}"

?

This is a BookResponse with a BookHeader array, where each array element
is a BookHeaderDtls JSON object.

In your original example, it is BookResponse with n number of BookHeader
single element arrays...

Can you try the option I prototyped ?

Sergey

Any help is appreciated...





--
View this message in context:
http://cxf.547215.n5.nabble.com/JSONProvider-unable-to-unmarshal-json-containing-list-of-elements-tp5715651p5718799.html

Sent from the cxf-user mailing list archive at Nabble.com.




--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to