Return-Path: X-Original-To: apmail-cxf-users-archive@www.apache.org Delivered-To: apmail-cxf-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA72BED48 for ; Sun, 6 Jan 2013 20:44:24 +0000 (UTC) Received: (qmail 34549 invoked by uid 500); 6 Jan 2013 20:44:24 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 34505 invoked by uid 500); 6 Jan 2013 20:44:24 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 34487 invoked by uid 99); 6 Jan 2013 20:44:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Jan 2013 20:44:23 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sberyozkin@gmail.com designates 209.85.215.180 as permitted sender) Received: from [209.85.215.180] (HELO mail-ea0-f180.google.com) (209.85.215.180) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Jan 2013 20:44:18 +0000 Received: by mail-ea0-f180.google.com with SMTP id f13so7090936eai.25 for ; Sun, 06 Jan 2013 12:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=Tg3bnzmyFHZRA5m1M/ocQ8DiISB8AoRF4nan6qtVVz0=; b=uSs08DrPxD/TDdjNB+wK0zvpdtk4RvH6a9Qj5OzGayp0oeJariVQCstsfrjwGOCkLz 972CJRO0Y6So4TL7JhifcmEuOY+bmvJhxIMxlRfcShYIXPb5FSyRdyfrG26hNdFcIYBk 49htaHwNwTUlxftSzuyZ7tL8zOe0wQy8MU85R2vej2VEM1+mwZeKgubHZxvX9DTuAXiG 0Hab9MR0ckUqYt8j5qUY1RGGSrZZf5dtnWRNCvRORIIBje/TvMTz3alA8AjMkFm4AOuZ 5Z2xrBHFpxDrU/ruxgy6hE96ErK+9pHVfUaSIj9Fr15Qddtme/frv2PY2p2fhpKJRfqQ 66zg== X-Received: by 10.14.194.4 with SMTP id l4mr161703590een.42.1357505037278; Sun, 06 Jan 2013 12:43:57 -0800 (PST) Received: from [10.39.0.31] ([87.252.227.100]) by mx.google.com with ESMTPS id l3sm126678117eem.14.2013.01.06.12.43.55 (version=SSLv3 cipher=OTHER); Sun, 06 Jan 2013 12:43:56 -0800 (PST) Message-ID: <50E9E209.6030001@gmail.com> Date: Sun, 06 Jan 2013 23:43:53 +0300 From: Sergey Beryozkin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: users@cxf.apache.org CC: jbright Subject: Re: JSONProvider unable to unmarshal json containing list of elements References: <1349368348311-5715651.post@n5.nabble.com> <506DBAEF.2090508@gmail.com> <1349430338548-5715787.post@n5.nabble.com> <506EB809.80508@gmail.com> <1349433785694-5715793.post@n5.nabble.com> <1349695821292-5716002.post@n5.nabble.com> <50734002.1020205@gmail.com> <1349786009066-5716150.post@n5.nabble.com> <5076BAB1.3050404@gmail.com> <1353397580042-5718799.post@n5.nabble.com> <50E9D7EF.1010009@gmail.com> In-Reply-To: <50E9D7EF.1010009@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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().readFrom(BookResponse.class, null, null, null, null, new ByteArrayInputStream(input.getBytes())); assertNotNull(response); List 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; @XmlElement(name = "BookHeader") public List getBookHeader() { return bookHeader; } public void setBookHeader(List 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 >> >> >> .... >> .... >> .... >> .... >> .... >> ...... >> >> > > 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