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 occurred during error handling, give up! Invalid type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}] [ERROR ] SRVE0777E: Exception thrown by application class 'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116' java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Invalid type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}] at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) at [internal classes] Caused by: org.apache.cxf.interceptor.Fault: Invalid type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}] at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:76) ... 1 more 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) ... 1 more
When I do a POST on the resource and the json object contains a property that is either a json array or a json object, the exception is thrown before the function is reached
Example JSON that causes this (if I remove the "c" property it works fine):
{
"a": "b",
"c": {
"d": "e"
}
}
The same error is thrown if "c" is an array:
{
"a": "b",
"c": [
{"d": "e"},
{"d": "f"},
{"d": "g"}
]
}
I have not added any libs of my own, all is what is included in WLP. If I run this example on WLP 8.5.5.3 it works fine. Any ideas what I am missing because I find it hard to believe that this simple sample expose a defect?
This is my resource:
RootResouce.java
package com.sample;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.ibm.json.java.JSONObject;
@Path("/hello")
public class RootResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postTest(JSONObject json) {
return Response.ok(json).build();
}
}
This is my app:
package com.sample;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyApp extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(RootResource.class);
return s;
}
}
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<description>Simple Test service</description>
<display-name>sample</display-name>
<servlet-name>sample</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.sample.MyApp</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<display-name>SimpleTest</display-name>
</web-app>