I have a restful web service, and the response is:
{
"cities": [{
"id": "1",
"name": "City 01",
"state": "A1"
}, {
"id": "2",
"name": "City 02",
"state": "A1"
}]
}
But I want this:
{
[{
"id": "1",
"name": "City 01",
"state": "A1"
}, {
"id": "2",
"name": "City 02",
"state": "A1"
}]
}
How I can configure JAX-RS to produces JSON without root node using only JAX-RS feature, and not implementation specific feature? My code needs to be portable across any appserver.
I had the same problem with Glassfish v3. I found this behavior depends on the JAX-RS implementation and switching to Codehaus’ Jackson JAX-RS implementation solved the problem for me.
If you’re using Glassfish as well, then you can solve the problem by adding
org.codehaus.jackson.jaxrsto your war as well as to theWEB-INF/web.xmlconfiguration as follows:Alternatively, you might be able to simply intercept the response in the client:
Replace
with