Exception thrown when posting JSON in JAX-RS app running on WLP 8.5.5.8

前端 未结 1 574
深忆病人
深忆病人 2021-01-16 14:25

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

相关标签:
1条回答
  • 2021-01-16 14:42

    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;
        }
    
    0 讨论(0)
提交回复
热议问题