You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Andreas Hartmann <an...@apache.org> on 2009/07/21 12:35:56 UTC

How to enable JsonWriter.DROP_ROOT_MODE?

Hi everyone,

I'm a total CXF newbie and want to setup a JAX-RS service to use with 
the DOJO JsonRestStore. ATM I'm using CXF 2.2.2.

Is there a way to configure the JSON marshalling not to insert a root 
element? I found out about the JsonWriter.DROP_ROOT_MODE parameter:

"Therefore it is possible to drop this root by initializing the 
internally used JsonWriter in a different mode." [1]

   new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);

Is it possible to configure CXF so that the JsonWriter is initialized 
with this parameter?


I have already read the thread "JSON in CXF - root element dropped", but 
it looks like I'd have to work with the trunk and make myself familiar 
with some CXF internals. Is there an easier way to achieve this?

Thanks a lot in advance for any hints!

[1] http://xstream.codehaus.org/json-tutorial.html

-- Andreas

-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


Re: How to enable JsonWriter.DROP_ROOT_MODE?

Posted by Sergey Beryozkin <se...@iona.com>.
Hi Andreas

I actually only had to add this property only and update one 'if' statement
checking if it was set for it to start working, as JSONProvider already has
a custom writer in place which drops the root element (when explicit
collections are returned), so it was an easy fix, hope it will actually work
for you :-) 

cheers, Sergey


Andreas Hartmann wrote:
> 
> Hi Sergey,
> 
> Sergey Beryozkin schrieb:
>> Ok, it's done now. Fix will be released next week, but you can try a
>> 2.3-snapshot tomorrow or try to do a fast build :
>> 1. mvn install -Pfastinstall
>> 2. cd api, mvn install
>> 3. cd ..\distribution, mvn install 
> 
> wow, thanks for taking care of this so quickly!
> 
>> Please register JSONProvider explicitly and set 'dropRootName' property
>> to
>> 'true'
> 
> Thanks for explaining!
> 
> -- Andreas
> 
>> 
>> thanks, Sergey
>> 
>> 
>> Sergey Beryozkin wrote:
>>> Hi
>>>
>>> I think we can quite easily support it, by registering a simple writer
>>> which will wrap the Jettison one and drop the root element. The "JSON in
>>> CXF - root element dropped" thread is more about wrapping the incoming
>>> sequence.
>>> I will just add a property to JSONProvider which will enable it to do
>>> it. 
>>>
>>> cheers, Sergey 
>>>
>>>
>>> Andreas Hartmann wrote:
>>>> Hi everyone,
>>>>
>>>> I'm a total CXF newbie and want to setup a JAX-RS service to use with 
>>>> the DOJO JsonRestStore. ATM I'm using CXF 2.2.2.
>>>>
>>>> Is there a way to configure the JSON marshalling not to insert a root 
>>>> element? I found out about the JsonWriter.DROP_ROOT_MODE parameter:
>>>>
>>>> "Therefore it is possible to drop this root by initializing the 
>>>> internally used JsonWriter in a different mode." [1]
>>>>
>>>>    new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
>>>>
>>>> Is it possible to configure CXF so that the JsonWriter is initialized 
>>>> with this parameter?
>>>>
>>>>
>>>> I have already read the thread "JSON in CXF - root element dropped",
>>>> but 
>>>> it looks like I'd have to work with the trunk and make myself familiar 
>>>> with some CXF internals. Is there an easier way to achieve this?
>>>>
>>>> Thanks a lot in advance for any hints!
>>>>
>>>> [1] http://xstream.codehaus.org/json-tutorial.html
>>>>
>>>> -- Andreas
>>>>
>>>> -- 
>>>> Andreas Hartmann, CTO
>>>> BeCompany GmbH
>>>> http://www.becompany.ch
>>>> Tel.: +41 (0) 43 818 57 01
>>>>
>>>>
>>>>
>>>
>> 
> 
> 
> -- 
> Andreas Hartmann, CTO
> BeCompany GmbH
> http://www.becompany.ch
> Tel.: +41 (0) 43 818 57 01
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-enable-JsonWriter.DROP_ROOT_MODE--tp24585380p24602082.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to enable JsonWriter.DROP_ROOT_MODE?

Posted by Andreas Hartmann <an...@apache.org>.
Hi Sergey,

Sergey Beryozkin schrieb:
> Ok, it's done now. Fix will be released next week, but you can try a
> 2.3-snapshot tomorrow or try to do a fast build :
> 1. mvn install -Pfastinstall
> 2. cd api, mvn install
> 3. cd ..\distribution, mvn install 

wow, thanks for taking care of this so quickly!

> Please register JSONProvider explicitly and set 'dropRootName' property to
> 'true'

Thanks for explaining!

-- Andreas

> 
> thanks, Sergey
> 
> 
> Sergey Beryozkin wrote:
>> Hi
>>
>> I think we can quite easily support it, by registering a simple writer
>> which will wrap the Jettison one and drop the root element. The "JSON in
>> CXF - root element dropped" thread is more about wrapping the incoming
>> sequence.
>> I will just add a property to JSONProvider which will enable it to do it. 
>>
>> cheers, Sergey 
>>
>>
>> Andreas Hartmann wrote:
>>> Hi everyone,
>>>
>>> I'm a total CXF newbie and want to setup a JAX-RS service to use with 
>>> the DOJO JsonRestStore. ATM I'm using CXF 2.2.2.
>>>
>>> Is there a way to configure the JSON marshalling not to insert a root 
>>> element? I found out about the JsonWriter.DROP_ROOT_MODE parameter:
>>>
>>> "Therefore it is possible to drop this root by initializing the 
>>> internally used JsonWriter in a different mode." [1]
>>>
>>>    new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
>>>
>>> Is it possible to configure CXF so that the JsonWriter is initialized 
>>> with this parameter?
>>>
>>>
>>> I have already read the thread "JSON in CXF - root element dropped", but 
>>> it looks like I'd have to work with the trunk and make myself familiar 
>>> with some CXF internals. Is there an easier way to achieve this?
>>>
>>> Thanks a lot in advance for any hints!
>>>
>>> [1] http://xstream.codehaus.org/json-tutorial.html
>>>
>>> -- Andreas
>>>
>>> -- 
>>> Andreas Hartmann, CTO
>>> BeCompany GmbH
>>> http://www.becompany.ch
>>> Tel.: +41 (0) 43 818 57 01
>>>
>>>
>>>
>>
> 


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


Re: How to enable JsonWriter.DROP_ROOT_MODE?

Posted by Sergey Beryozkin <se...@iona.com>.
Ok, it's done now. Fix will be released next week, but you can try a
2.3-snapshot tomorrow or try to do a fast build :
1. mvn install -Pfastinstall
2. cd api, mvn install
3. cd ..\distribution, mvn install 

Please register JSONProvider explicitly and set 'dropRootName' property to
'true'

thanks, Sergey


Sergey Beryozkin wrote:
> 
> Hi
> 
> I think we can quite easily support it, by registering a simple writer
> which will wrap the Jettison one and drop the root element. The "JSON in
> CXF - root element dropped" thread is more about wrapping the incoming
> sequence.
> I will just add a property to JSONProvider which will enable it to do it. 
> 
> cheers, Sergey 
> 
> 
> Andreas Hartmann wrote:
>> 
>> Hi everyone,
>> 
>> I'm a total CXF newbie and want to setup a JAX-RS service to use with 
>> the DOJO JsonRestStore. ATM I'm using CXF 2.2.2.
>> 
>> Is there a way to configure the JSON marshalling not to insert a root 
>> element? I found out about the JsonWriter.DROP_ROOT_MODE parameter:
>> 
>> "Therefore it is possible to drop this root by initializing the 
>> internally used JsonWriter in a different mode." [1]
>> 
>>    new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
>> 
>> Is it possible to configure CXF so that the JsonWriter is initialized 
>> with this parameter?
>> 
>> 
>> I have already read the thread "JSON in CXF - root element dropped", but 
>> it looks like I'd have to work with the trunk and make myself familiar 
>> with some CXF internals. Is there an easier way to achieve this?
>> 
>> Thanks a lot in advance for any hints!
>> 
>> [1] http://xstream.codehaus.org/json-tutorial.html
>> 
>> -- Andreas
>> 
>> -- 
>> Andreas Hartmann, CTO
>> BeCompany GmbH
>> http://www.becompany.ch
>> Tel.: +41 (0) 43 818 57 01
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-enable-JsonWriter.DROP_ROOT_MODE--tp24585380p24591283.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to enable JsonWriter.DROP_ROOT_MODE?

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

I think we can quite easily support it, by registering a simple writer which
will wrap the Jettison one and drop the root element. The "JSON in CXF -
root element dropped" thread is more about wrapping the incoming sequence.
I will just add a property to JSONProvider which will enable it to do it. 

cheers, Sergey 


Andreas Hartmann wrote:
> 
> Hi everyone,
> 
> I'm a total CXF newbie and want to setup a JAX-RS service to use with 
> the DOJO JsonRestStore. ATM I'm using CXF 2.2.2.
> 
> Is there a way to configure the JSON marshalling not to insert a root 
> element? I found out about the JsonWriter.DROP_ROOT_MODE parameter:
> 
> "Therefore it is possible to drop this root by initializing the 
> internally used JsonWriter in a different mode." [1]
> 
>    new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
> 
> Is it possible to configure CXF so that the JsonWriter is initialized 
> with this parameter?
> 
> 
> I have already read the thread "JSON in CXF - root element dropped", but 
> it looks like I'd have to work with the trunk and make myself familiar 
> with some CXF internals. Is there an easier way to achieve this?
> 
> Thanks a lot in advance for any hints!
> 
> [1] http://xstream.codehaus.org/json-tutorial.html
> 
> -- Andreas
> 
> -- 
> Andreas Hartmann, CTO
> BeCompany GmbH
> http://www.becompany.ch
> Tel.: +41 (0) 43 818 57 01
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-enable-JsonWriter.DROP_ROOT_MODE--tp24585380p24586592.html
Sent from the cxf-user mailing list archive at Nabble.com.