I have a restful web service, and the response is:
{
\"cities\": [{
\"id\": \"1\",
\"name\": \"City 01\",
\"state\": \"A1\"
}
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.jaxrs to your war as well as to the WEB-INF/web.xml configuration as follows:
RESTful Services
com.sun.jersey.spi.container.servlet.ServletContainer
com.sun.jersey.config.property.resourceConfigClass
com.sun.jersey.api.core.PackagesResourceConfig
com.sun.jersey.config.property.packages
you.service.packages;org.codehaus.jackson.jaxrs
1
RESTful Services
/your/rest/path/*
Alternatively, you might be able to simply intercept the response in the client:
function consumesCity(json) {
...
}
Replace
... consumesCity(json) ...
with
function preprocess(json) {
return json.city;
}
... consumesCity(preprocess(json)) ...