I have a very simple Java app using JAX-RS, running on WLP 8.5.5.8. When I post JSON that is a composite structure I get this error:
[ERROR ] Error
Looking a little further with the code provided, I see this in the exception:
Caused by: java.lang.IllegalArgumentException: Invalid type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}]
at com.ibm.json.java.JSONObject.put(JSONObject.java:241)
at org.codehaus.jackson.map.deser.MapDeserializer._readAndBind(MapDeserializer.java:244)
at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:166)
at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:24)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:1961)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:889)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1307)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:847)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:810)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:255)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:85)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307
Maybe the default json provider changed between jax-rs 1.1 and 2.0? Deserializing request data with Jackson into a json4j object is not going well. Setting the provider like this seems to allow it to work:
import com.ibm.websphere.jaxrs.providers.json4j.JSON4JArrayProvider;
import com.ibm.websphere.jaxrs.providers.json4j.JSON4JObjectProvider;
public class MyApp extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(RootResource.class);
s.add(JSON4JObjectProvider.class);
s.add(JSON4JArrayProvider.class);
return s;
}