I had the same issue with Glassfish v3. I found that this behavior is dependent on the JAX-RS implementation, and switching to the Codehaus Jackson JAX-RS implementation has solved the problem for me.
If you also use Glassfish, you can solve the problem by adding org.codehaus.jackson.jaxrs to your war, as well as to the WEB-INF/web.xml as follows:
<servlet> <servlet-name>RESTful Services</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>you.service.packages;org.codehaus.jackson.jaxrs</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>RESTful Services</servlet-name> <url-pattern>/your/rest/path/*</url-pattern> </servlet-mapping>
Alternatively, you can simply intercept the response in the client:
function consumesCity(json) { ... }
Replace
... consumesCity(json) ...
from
function preprocess(json) { return json.city; } ... consumesCity(preprocess(json)) ...
Kim burgaard
source share