Escaping & (ampersands) in an XML response for links

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Escaping & (ampersands) in an XML response for links

naresh
REST responses sometimes contain links or URIs that point a user to sub-resources.

When query parameters are involved, and the response is XML, what should happen to & (ampersand) characters that join the query params?

This is what the default encoding looks like:

<url>.../resource/subresource?param1=value1& amp ;param2=value2</url>

The & is escaped to & amp ; which is correct for an XML parser. Note, I've deliberately inserted spaces so that the message shows up in the forum, as I intended.

However when the same URL is submitted as a request, @QueryParam("param2") does not work in capturing the value of the parameter.

Jersey finds that the 2nd parameter is amp;param2 and not param2.
So @QueryParam("amp;param2") will work is the user decides to pick up the XML url as is and issue a GET.

Or, should the XML response be:
<url>.../resource/subresource?param1=value1 & param2=value2</url>

where the & is not escaped/encoded at all.


Loading...