cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sergey.beryoz...@iona.com>
Subject RE: JSON in CXF - root element dropped
Date Fri, 10 Jul 2009 09:01:21 GMT

Hi Paul

I think I may want to ask Dan to initiate a 2.2.3-SNAPSHOT Hudson build. All
the changes are local to JSONProvider so in meantime 
you might want to copy the source from the trunk or 2.2.3-SNAPSHOT and
register it as a custom provider, I'll be applying few minor 
updates to it (proper exception reporting, etc) but it won't affect what it
already does now...

cheers, Sergey


Paul Wilton wrote:
> 
> Hi Sergey
> Sounds awesome - thanks.
> I have tried 2.2.3-SNAPSHOT using the bundle-jaxrs dependency, but the
> JSONProvider doesn't seem to have the new methods in it.
> I am using following dependency + repo  (note: I have cleaned and pulled
> the latest snapshot down)
> 
> <dependency>
>     <groupId>org.apache.cxf</groupId>
>     <artifactId>cxf-bundle-jaxrs</artifactId>
>     <version>2.2.3-SNAPSHOT</version>
> </dependency>
> 
> <repository>
>     <id>apache-snapshots</id>
>     <name>repository.apache.org snapshots repo</name>
>     <url>http://repository.apache.org/snapshots/</url>
> </repository>
> 
> 
> -----Original Message-----
> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com] 
> Sent: 09 July 2009 18:09
> To: users@cxf.apache.org
> Subject: RE: JSON in CXF - root element dropped
> 
> 
> Hi
> 
> It should be fixed now on the trunk/2.2.3-snapshot
> 
> There's a number of ways one can deal with it. In all cases a
> 'supportUnwrapped' property has to be set on the json provider :
> JSONProvider provider = new JSONProvider();
> provider.setSupportUnwrapped(true);
> 
> and then one of 3 options:
> 
> 1. provider.setWrapperName("tags");
>     or, if namespace qualified
>     provider.setWrapperName("ns1.tags");
> 2. Map<String, String> map = new HashMap<String, String>();
>     map.put(Tags.class.getName(), "tags")
>     // etc for all known classes
> 3. finally, one can let the provider itself to figure out the name of
> the
> wrapper, it will check XMLRootElement first, and then will 
> attempt to do some more advanced checks in case this info is available
> on
> ObjectFactories, etc
> 
> 2&3 can be combined.
> Also, it is not a requirement now to register a namespace map for cases
> when
> namespace prefixed are needed to be serialized, they 
> will be allocated by default if needed...
> 
> You might want to try the latest provider source and see if it can
> consume
> the service response now, it would be helpful
> thanks, Sergey
> 
> 
> Paul Wilton wrote:
>> 
>> That would be awesome if you could get it into the 2.2.3 release
>> Cheers
>> Paul
>> 
>> -----Original Message-----
>> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com] 
>> Sent: 06 July 2009 17:18
>> To: users@cxf.apache.org
>> Subject: RE: JSON in CXF - root element dropped
>> 
>> 
>> Hi,
>> 
>> Yeah, if it's only a single root element which is dealt with and this
>> property is set then it would be easy for JSONProvider to wrap again,
>> but if
>> it is not set then it can try to deduce the node name automatically
>> given
>> that in its readFrom() method it has an access to the parent bean
>> instance... Actually, I haven't thought about injecting the node name
>> property but for simple cases it will make it easy and fast indeed for
>> JSONProvider.
>> 
>> So if it sounds like it should work then I will do it in time for the
>> 2.2.3
>> release. In meantime, you might want to create a custom provider by
>> slightly
>> modifying the existing one (yet again :-), using your idea of
> injecting
>> a
>> node name property.
>> 
>> thanks, Sergey
>> 
>> 
>> Paul Wilton wrote:
>>> 
>>> Yep - 
>>> that sounds like something that could work :
>>> just to be clear, you are suggesting simply adding a setter on
>>> JSONProvider 
>>> for example  setWrappedNodeElement(String nodeName) 
>>> that would decorate the InputStream with the nodeName so the JAXB
>>> unmarshalling would go ahead as normal, and unmarshal the decorated
>> JSON
>>> into the bean (specified by the node name)
>>> 
>>> Paul
>>> 
>>> 
>>> -----Original Message-----
>>> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com] 
>>> Sent: 06 July 2009 16:57
>>> To: users@cxf.apache.org
>>> Subject: Re: JSON in CXF - root element dropped
>>> 
>>> 
>>> Hi Paul
>>> 
>>> Yes, I remember we were talking with Tony about it. I think Tony
>>> expressed
>>> some interest in enhancing the CXF JSON provider but the idea was to
>> use
>>> JSON annotations so that users could choose not to depend on the
>>> JAXB-driven
>>> serialization. People are often referring to Jackson but I don't know
>> if
>>> it's capable of handling JAXB beans fully. Dejan has released
> Jettison
>>> 1.1
>>> and fixed some blockers so, as far as JSON & JAXB is concerned we
> feel
>>> we're
>>> kind of ok with Jettison being the default JAXB provider for now.
>>> Perhaps we
>>> can see some more Jettison micro releases going forward. In fact,
> I've
>>> talked to him today about what appears to be a very similar issue :
>>> 
>>>
>>
> http://www.nabble.com/Supprot-for-wrapped-unwrapped-styles-in-Mapped-con
>>> vention-for-JSON-td24319534.html
>>> 
>>> It's something that a JSON library probably can't fix on its own as
> it
>>> does
>>> not know what parent object a given JSON sequence belongs to.
>>> 
>>> Does the idea of replacing an InputStream with a new one which would
>>> decorate {the unwrapped sequence} with "{jaxb-name-of-parent-bean:" &
>>> "}"
>>> sound reasonable ? This can be done in the JSONProvider quite
>> easily...
>>> 
>>> cheers, Sergey
>>> 
>>> 
>>> Paul Wilton wrote:
>>>> 
>>>> Hi Sergey,
>>>> 
>>>> Recall this conversation (back in Feb 2009), about consuming JSON
>>> where
>>>> a list of objects has had the root element dropped (in XML response
>>> the
>>>> root element would remain) :
>>>> 
>>>>
>>>
>>
> http://mail-archives.apache.org/mod_mbox/cxf-dev/200902.mbox/%3C019d01c9
>>>> 8b9b$7a4ae450$0c02050a@emea.progress.com%3E
>>>> 
>>>> I am also in position of trying to consume a Web service with no
> root
>>>> element in the JSON response, and the standard JSON provider can't
>>>> handle it because of lack of the root element.
>>>> 
>>>> You said :
>>>> "I'd happy to consider replacing the existing one (JSONProvider)
> with
>>> a
>>>> better quality one if it were JAXB
>>>> driven as a number of users depend on it 
>>>> being JAXB aware, such that we can also preserve the existing
>> features
>>>> like the ability to
>>>> schema-validate, which should not be a 
>>>> problem if it were JAXB-aware."
>>>> 
>>>> Did this get taken any further, and if not, is something that could
>> be
>>>> addressed?
>>>> 
>>>> Thanks
>>>> Paul 
>>>> This e-mail (and any attachments) is confidential and may contain
>>> personal
>>>> views which are not the views of the BBC unless specifically stated.
>>> If
>>>> you have received it in error, please delete it from your system. Do
>>> not
>>>> use, copy or disclose the information in any way nor act in reliance
>>> on it
>>>> and notify the sender immediately.
>>>>  
>>>> Please note that the BBC monitors e-mails sent or received. Further
>>>> communication will signify your consent to this
>>>> 
>>>> This e-mail has been sent by one of the following wholly-owned
>>>> subsidiaries of the BBC:
>>>>  
>>>> BBC Worldwide Limited, Registration Number: 1420028 England,
>>> Registered
>>>> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
>>>> BBC World News Limited, Registration Number: 04514407 England,
>>> Registered
>>>> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
>>>> BBC World Distribution Limited, Registration Number: 04514408,
>>> Registered
>>>> Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
>>>> 
>>>> 
>>> 
>>> -- 
>>> View this message in context:
>>>
>>
> http://www.nabble.com/Re%3A-JSON-in-CXF---root-element-dropped-tp2435755
>>> 1p24358143.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/Re%3A-JSON-in-CXF---root-element-dropped-tp2435755
>> 1p24358527.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Re%3A-JSON-in-CXF---root-element-dropped-tp2435755
> 1p24414226.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-JSON-in-CXF---root-element-dropped-tp24357551p24423936.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message