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 EDC3F18618 for ; Mon, 22 Jun 2015 21:04:58 +0000 (UTC) Received: (qmail 30685 invoked by uid 500); 22 Jun 2015 21:04:58 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 30608 invoked by uid 500); 22 Jun 2015 21:04:58 -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 30595 invoked by uid 99); 22 Jun 2015 21:04:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jun 2015 21:04:58 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of demablogia@gmail.com designates 209.85.217.175 as permitted sender) Received: from [209.85.217.175] (HELO mail-lb0-f175.google.com) (209.85.217.175) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jun 2015 21:02:43 +0000 Received: by lbbvz5 with SMTP id vz5so68523546lbb.0 for ; Mon, 22 Jun 2015 14:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=8rk8+j4ep430odJMJzmrYHpv0NSepWzpTPzqc2Y9b/8=; b=oi2q6z2wHxkKZYWN0alJyLpVsjBIe55zwTGpgK28RDQlvIUcxISwfDiewpMjTgVs7e FqGNn5TUZWymbdzIIwvNbRU82XgNzi84p6nvSUzYqpZWNfAeE6dNmgfA4tQ3xoHnju8v hW2ddGN0bVeSj/NLEE93ZZoQGG6uXkOpN/Bdbwn7fht7WtfCh2Pp06d85gH0oNmy+9Ra QaTuNu8FQD6dn8VEVR2jFiz3X2qXWqhIaOf+vGWVa33rtaERnA+UfbZ2v/ZiElaMI1Zx LBdRORfqH0Zqbpqi3q7pQ3FAW1N+HjXDLfg4N++qN3t8nc24Jt2YMXn/120C2f1ZQOM1 Vdmg== X-Received: by 10.152.37.102 with SMTP id x6mr31597132laj.69.1435007071938; Mon, 22 Jun 2015 14:04:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.97.65 with HTTP; Mon, 22 Jun 2015 14:04:12 -0700 (PDT) In-Reply-To: <5588734E.9010305@gmail.com> References: <5587ED73.2060202@gmail.com> <5587F603.9020802@gmail.com> <55881D6B.6020402@gmail.com> <5588734E.9010305@gmail.com> From: =?UTF-8?Q?Jose_Mar=C3=ADa_Zaragoza?= Date: Mon, 22 Jun 2015 23:04:12 +0200 Message-ID: Subject: Re: POST an JSON array by using Jettison1.3.5 To: "users@cxf.apache.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 2015-06-22 22:42 GMT+02:00 Sergey Beryozkin : > I've updated that test locally: > > provider.setDropRootElement(true); > provider.setArrayKeys(Arrays.asList("parameterList")); > provider.setOutDropElements(Arrays.asList("parameterList")); > provider.setDropElementsInXmlStream(false); > > and it produces > > [{"name":"param"}] > or > [{"name":"param"},{"name":"param"}] > > Not ideal that certain properties have to be named but JAXB sends only > XMLStreamWriter events to Jettison. > > Plenty of other options are available. > Andriy Redko did a work on JsrJsonpProvider which supports JSONP JSR, > I recently added JsonObjectMapProvider which supports simple > JsonObjectMapReaderWriter, those options are in CXF starting from 3.0.x a= nd > Jackson should do well too > > HTH, Sergey Thank for your help. I'll do tests on my own Regards > > > On 22/06/15 17:13, Jose Mar=C3=ADa Zaragoza wrote: >> >> 2015-06-22 16:36 GMT+02:00 Sergey Beryozkin : >>> >>> Hi >>> >>> Have a look at >>> >>> https://github.com/apache/cxf/blob/master/rt/rs/extensions/providers/sr= c/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java#L215 >>> >>> Cheers, Sergey >> >> >> >> Thanks >> >> I've seen that this test checks if JSON provider can generate >> [{"parameterList":{"name":"param"}}] >> And works fine with >> >> provider.setSerializeAsArray(true); >> provider.setDropElementsInXmlStream(false); >> >> >> But I need [{"name":"param"}] >> >> And I don't know how achieve that >> >> >> >>> >>> On 22/06/15 15:30, Jose Mar=C3=ADa Zaragoza wrote >>>> >>>> >>>> 2015-06-22 13:48 GMT+02:00 Sergey Beryozkin : >>>>> >>>>> >>>>> When you use a collection, JSONProvider wraps it internally to suppor= t >>>>> a >>>>> common path where a JAXB bean is provided and serialized, so >>>>> 'dropRootElement' drops that internally added root. >>>>> Create a basic CardTypes bean wrapping a collection, use >>>>> webClient.post(), >>>>> and these properties: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Let me know if it works >>>>> Sergey >>>>> >>>> >>>> Thanks, but I'm afraid it doesn't work for me >>>> >>>> >>>> My code >>>> >>>> // List card2 >>>> //CardType has @XmlRootElement annotation >>>> List list =3D new ArrayList(); >>>> >>>> for (String c2:card2) >>>> { >>>> CardType cardType =3D this.factory.createCardType(); >>>> cardType.setIcc(c2); >>>> >>>> list.add(cardType); >>>> } >>>> >>>> javax.ws.rs.core.Response r =3D >>>> this.client.path("/temp").postCollection(list,CardType.class); >>>> // >>>> >>>> >>>> Without >>>> >>>> >>>> >>>> {"cardType":[{"icc":8934077600006637935},{"icc":"22222222222222222222"= }]} >>>> >>>> >>>> With >>>> >>>> {"cardType":[8934077600006637935,"22222222222222222222"]} >>>> >>>> >>>> Note thart "icc" fieldname is missing >>>> >>>> >>>> >>>> I'll try to upgrade to jettison 1.3.7 and cxf 2.7.10 ( if you think >>>> that could be the reason of my problem ) >>>> >>>> >>>> If you have any JAXB class that I could test , I would appreciate >>>> >>>> Regards >>>> >>>> >>>> >>>>> >>>>> >>>>> On 22/06/15 12:28, Jose Mar=C3=ADa Zaragoza wrote: >>>>>> >>>>>> >>>>>> >>>>>> 2015-06-22 13:11 GMT+02:00 Sergey Beryozkin : >>>>>>> >>>>>>> >>>>>>> >>>>>>> Hi >>>>>>> >>>>>>> CXF JettisonProvider is only capable of supporting JAXB-generated >>>>>>> events, >>>>>>> it >>>>>>> does not deal directly with JSONObjects. >>>>>>> What is the problem you are seeing with JAXB ? Can not have a >>>>>>> sequence >>>>>>> starting immediately from "[" ? That should be possible to configur= e >>>>>>> with >>>>>>> JettisonProvider with properties like 'dropRootElement': true, >>>>>>> dropElementsInXmlStream: false, serializeAsArray: true >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Right: I can not have a sequence starting immediately from "[" >>>>>> >>>>>> My settings : >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> My JAXB class >>>>>> >>>>>> @XmlRootElement >>>>>> @XmlAccessorType(XmlAccessType.FIELD) >>>>>> @XmlType(name =3D "CardType", propOrder =3D { "line", "icc", "status= Code" >>>>>> }) >>>>>> public class CardType >>>>>> { >>>>>> >>>>>> @XmlElement(required =3D true) >>>>>> protected String line; >>>>>> @XmlElement(required =3D true) >>>>>> protected String icc; >>>>>> @XmlElement(name =3D "status_code") >>>>>> protected String statusCode; >>>>>> >>>>>> >>>>>> The call: >>>>>> List l =3D new ArrayList(); >>>>>> ... >>>>>> .... >>>>>> this.client.path("/temp").postCollection(l, CardType.class); >>>>>> >>>>>> >>>>>> and I send >>>>>> >>>>>> >>>>>> >>>>>> {"cardType":[{"icc":8934077600006637935},{"icc":"2222222222222222222= 2"}]} >>>>>> >>>>>> I would like to send >>>>>> [{"icc":8934077600006637935},{"icc":"22222222222222222222"}] >>>>>> >>>>>> >>>>>> Extra: I don't know why it sendsthe first value without quotes ... >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> Cheers, Sergey >>>>>>> >>>>>>> >>>>>>> On 22/06/15 11:42, Jose Mar=C3=ADa Zaragoza wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Hello: >>>>>>>> >>>>>>>> I would like to POST a JSON array to a REST service >>>>>>>> >>>>>>>> Something like >>>>>>>> >>>>>>>> [ >>>>>>>> >>>>>>>> { >>>>>>>> "name" : "xxxxx", >>>>>>>> "value" : "111111" >>>>>>>> }, >>>>>>>> { >>>>>>>> "name" : "yyyyyy", >>>>>>>> "value" : "222222" >>>>>>>> } >>>>>>>> >>>>>>>> ] >>>>>>>> >>>>>>>> I'm using CXF 2.7.8 + Jettison 1.3.5 >>>>>>>> >>>>>>>> I usually implement it by JAXB classes , but I don't get achieving >>>>>>>> it >>>>>>>> If I try with a JSONArray >>>>>>>> >>>>>>>> this.client.path("/test/").post(myJSONArray) >>>>>>>> >>>>>>>> I get >>>>>>>> >>>>>>>> No message body writer has been found for class : class >>>>>>>> org.codehaus.jettison.json.JSONArray >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Any idea ? >>>>>>>> >>>>>>>> Thanks and regards >>>>>>>> >>>>>>> >>>>> >>> >>> >>> -- >>> Sergey Beryozkin >>> >>> Talend Community Coders >>> http://coders.talend.com/ >>> >>> Blog: http://sberyozkin.blogspot.com > > > > -- > Sergey Beryozkin > > Talend Community Coders > http://coders.talend.com/ > > Blog: http://sberyozkin.blogspot.com