You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by trimble <Fr...@trimble.com> on 2013/05/06 20:46:31 UTC

forwardslash being escaped from json response

I have a JAX-RS service return a simple java object that contains "/" in the
String value and that will be escaped into "\/". How can I stop this
behavior? 

	@GET	
	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	@Path("{id}")
	public Vehicle getVehicle(@PathParam("id") String id) {
            // cook a Vehicle instance that has one of the field: String
urlStr = "http://test.com/test/";
            return veh;
        }

the result I got for that field will be: "http:\/\/test.com\/test\/". 



--
View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by Sergey Beryozkin <sb...@gmail.com>.
The forward slashes are now not escaped by default on the 
trunk/branches, unless a "</" combination is processed.

Cheers, Sergey
On 19/08/14 17:33, Sergey Beryozkin wrote:
> Hi,
> On 19/08/14 14:33, franck wrote:
>> Thanks Sergey Beryozkin.
>>
>> Will you create a new JIRA ticket for this purpose or is it already
>> covered
>> by an existing ticket?
>>
>> Do you know approximately when 1.3.6 should be out?
>>
> I'd say it's a few weeks away from now. I started working toward it,
> fixed few minor issues, few more including this one needs to be addressed.
>
> CXF Jettison-based JSONProvider will need to have a new configuration
> property added once 1.3.6 has been released. I'll update you once I
> start working on it
>
> Sergey
>
>> Many thanks
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5747957.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>



Re: forwardslash being escaped from json response

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 19/08/14 14:33, franck wrote:
> Thanks Sergey Beryozkin.
>
> Will you create a new JIRA ticket for this purpose or is it already covered
> by an existing ticket?
>
> Do you know approximately when 1.3.6 should be out?
>
I'd say it's a few weeks away from now. I started working toward it, 
fixed few minor issues, few more including this one needs to be addressed.

CXF Jettison-based JSONProvider will need to have a new configuration 
property added once 1.3.6 has been released. I'll update you once I 
start working on it

Sergey

> Many thanks
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5747957.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: forwardslash being escaped from json response

Posted by franck <fr...@gmail.com>.
Thanks Sergey Beryozkin.

Will you create a new JIRA ticket for this purpose or is it already covered
by an existing ticket?

Do you know approximately when 1.3.6 should be out?

Many thanks





--
View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5747957.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 14/08/14 10:17, franck wrote:
> Sergey Beryozkin
>
> You said :
> Sergey Beryozkin wrote
>> apparently it is a default in some cases but proper JSON libraries
>> should allow for configuring it. I'll deal with it in the next Jettison
>> release, I'll keep you up-to-date.
>>
>> Please check if Jackson can do it in meantime
>>
>> Sergey
>
> I was wondering if you have eventually done this as I found no example on
> the internet as to how to configure jettison NOT to escape forward slashes.
No, but as it happens I started doing some work toward Jettison 1.3.6 
release, so I'll take care of it.

Cheers, Sergey
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5747813.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: forwardslash being escaped from json response

Posted by franck <fr...@gmail.com>.
Sergey Beryozkin

You said :
Sergey Beryozkin wrote
> apparently it is a default in some cases but proper JSON libraries 
> should allow for configuring it. I'll deal with it in the next Jettison 
> release, I'll keep you up-to-date.
> 
> Please check if Jackson can do it in meantime
> 
> Sergey

I was wondering if you have eventually done this as I found no example on
the internet as to how to configure jettison NOT to escape forward slashes.





--
View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5747813.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by trimble <Fr...@trimble.com>.
Thanks Glen and Sergey. That solved the escape issue I run into. but with
Jackson provider it seems lost other features that cxf json provider
provided. 

for example, I have the a jaxb annotated A class that has a list of fields
with one Object field: 
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class A {
	String x;
        @XmlAnyElement(lax=true)
	Object obj;
...
with cxf json provider, I can get it work with both xml/json. most
importantly I can assign the obj to different class such as B1.class or
B2.class at run time and get the json marshaling results correctly (except
the escape issue):
{"x":"x value","b1":{"b1_id":"b1_id value"}} or {"x":"x
value","b2":{"b2_id":"b2_id value"}}

using jackson provider it won't work with json unless the @JsonProperty
being put for every field and I also lost the nice run time binding, instead
I got "obj" all the time:
{"x":"x value","obj":{"b1_id":"b1_id value"}} or {"x":"x
value","obj":{"b2_id":"b2_id value"}}

thanks again for the help,





--
View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5727380.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by Glen Mazza <gl...@gmail.com>.
This should help: 
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jackson

Glen

On 05/06/2013 05:18 PM, trimble wrote:
> Sergey,
> If I use org.codehaus.jackson.map.ObjectMapper (I guess that's from Jackson)
> to convert the object to string and return it, it will not have this
> behavior. how can I assign a json provider from Jackson in the beans.xml?
> Currently I am using <bean id="jsonProvider"
> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
> Thanks for the help!
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5727315.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: forwardslash being escaped from json response

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 06/05/13 22:18, trimble wrote:
> Sergey,
> If I use org.codehaus.jackson.map.ObjectMapper (I guess that's from Jackson)
> to convert the object to string and return it, it will not have this
> behavior. how can I assign a json provider from Jackson in the beans.xml?
> Currently I am using<bean id="jsonProvider"
> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
> Thanks for the help!
>
Well, you'd just need to use the name of Jackson provider and likely 
inject ObjectMapper into it within the <bean> declaration

Sergey
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5727315.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by trimble <Fr...@trimble.com>.
Sergey,
If I use org.codehaus.jackson.map.ObjectMapper (I guess that's from Jackson)
to convert the object to string and return it, it will not have this
behavior. how can I assign a json provider from Jackson in the beans.xml?
Currently I am using <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
Thanks for the help! 



--
View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304p5727315.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: forwardslash being escaped from json response

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 06/05/13 19:46, trimble wrote:
> I have a JAX-RS service return a simple java object that contains "/" in the
> String value and that will be escaped into "\/". How can I stop this
> behavior?
>
> 	@GET	
> 	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> 	@Path("{id}")
> 	public Vehicle getVehicle(@PathParam("id") String id) {
>              // cook a Vehicle instance that has one of the field: String
> urlStr = "http://test.com/test/";
>              return veh;
>          }
>
> the result I got for that field will be: "http:\/\/test.com\/test\/".
>
I'm looking at some of StackOverflow posts like
http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped

apparently it is a default in some cases but proper JSON libraries 
should allow for configuring it. I'll deal with it in the next Jettison 
release, I'll keep you up-to-date.

Please check if Jackson can do it in meantime

Sergey

>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/forwardslash-being-escaped-from-json-response-tp5727304.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