cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose María Zaragoza <demablo...@gmail.com>
Subject Re: POST an JSON array by using Jettison1.3.5
Date Mon, 22 Jun 2015 21:04:12 GMT
2015-06-22 22:42 GMT+02:00 Sergey Beryozkin <sberyozkin@gmail.com>:
> 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 and
> 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ía Zaragoza wrote:
>>
>> 2015-06-22 16:36 GMT+02:00 Sergey Beryozkin <sberyozkin@gmail.com>:
>>>
>>> Hi
>>>
>>> Have a look at
>>>
>>> https://github.com/apache/cxf/blob/master/rt/rs/extensions/providers/src/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ía Zaragoza wrote
>>>>
>>>>
>>>> 2015-06-22 13:48 GMT+02:00 Sergey Beryozkin <sberyozkin@gmail.com>:
>>>>>
>>>>>
>>>>> When you use a collection, JSONProvider wraps it internally to support
>>>>> 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:
>>>>>
>>>>> <property name="dropRootElement" value="true" />
>>>>> <!-- Ensures that the exclusion occurs directly in Jettison and not
in
>>>>> the
>>>>> internal XMLStreamWriter -->
>>>>> <property name="dropElementsInXmlStream" value="false" />
>>>>> <property name="serializeAsArray" value="true"/>
>>>>>
>>>>> Let me know if it works
>>>>> Sergey
>>>>>
>>>>
>>>> Thanks, but I'm afraid it doesn't work for me
>>>>
>>>>
>>>> My code
>>>>
>>>> // List<String> card2
>>>> //CardType has @XmlRootElement annotation
>>>> List<CardType> list = new ArrayList<CardType>();
>>>>
>>>> for (String c2:card2)
>>>> {
>>>>        CardType cardType = this.factory.createCardType();
>>>>        cardType.setIcc(c2);
>>>>
>>>>        list.add(cardType);
>>>> }
>>>>
>>>> javax.ws.rs.core.Response r =
>>>> this.client.path("/temp").postCollection(list,CardType.class);
>>>> //
>>>>
>>>>
>>>> Without   <property name="dropElementsInXmlStream" value="false" />
>>>>
>>>>
>>>>
>>>> {"cardType":[{"icc":8934077600006637935},{"icc":"22222222222222222222"}]}
>>>>
>>>>
>>>> With  <property name="dropElementsInXmlStream" value="false" />
>>>>
>>>>    {"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ía Zaragoza wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> 2015-06-22 13:11 GMT+02:00 Sergey Beryozkin <sberyozkin@gmail.com>:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 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 configure
>>>>>>> with
>>>>>>> JettisonProvider with properties like 'dropRootElement': true,
>>>>>>> dropElementsInXmlStream: false, serializeAsArray: true
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Right: I can not have a sequence starting immediately from "["
>>>>>>
>>>>>> My settings :
>>>>>>
>>>>>>     <property name="dropRootElement" value="true" />
>>>>>>     <property name="supportUnwrapped" value="true" />
>>>>>>     <property name="serializeAsArray" value="true"/>
>>>>>>     <property name="ignoreEmptyArrayValues" value="true"/>
>>>>>>
>>>>>>
>>>>>> My JAXB class
>>>>>>
>>>>>> @XmlRootElement
>>>>>> @XmlAccessorType(XmlAccessType.FIELD)
>>>>>> @XmlType(name = "CardType", propOrder = { "line", "icc", "statusCode"
>>>>>> })
>>>>>> public class CardType
>>>>>> {
>>>>>>
>>>>>> @XmlElement(required = true)
>>>>>> protected String line;
>>>>>> @XmlElement(required = true)
>>>>>> protected String icc;
>>>>>> @XmlElement(name = "status_code")
>>>>>> protected String statusCode;
>>>>>>
>>>>>>
>>>>>> The call:
>>>>>> List<CardType> l = new ArrayList<CardType>();
>>>>>> ...
>>>>>> ....
>>>>>> this.client.path("/temp").postCollection(l, CardType.class);
>>>>>>
>>>>>>
>>>>>> and I send
>>>>>>
>>>>>>
>>>>>>
>>>>>> {"cardType":[{"icc":8934077600006637935},{"icc":"22222222222222222222"}]}
>>>>>>
>>>>>> 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ía 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

Mime
View raw message