Details
-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
3.0-beta-5
-
None
-
None
Description
I've created a custom ExceptionMapper in which I intend to return the exception as JSON. The toResponse method is implemented as:
return Response.serverError().entity(exception).build();
I'm throwing an exception from a method which returns a List<User>. My ExceptionMapper is called, but instead of the expected JSON I get a standard Tomcat exception page reporting org.jboss.resteasy.spi.UnhandledException: org.codehaus.jackson.map.JsonMappingException: Incompatible types: declared root type ([collection type; class java.util.List, contains [simple type, class my.stuff.User]]) vs my.stuff.exception.IllegalArgumentRestException.
Some digging revealed that the issue appears to be in org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse starting on line 54, where if there is no generic type then the generic type is retrieved from the method. While that is certainly appropriate when the method succeeds, it is not appropriate when the jaxrsResponse.getEntityClass() is entirely unrelated to jaxrsResponse.getGenericType(). It might be worthwhile to add an additional if-statment like:
if (generic instanceof ParameterizedType
&& ((ParameterizedType) generic).getRawType() instanceof Class
&& !((Class<?>) ((ParameterizedType) generic).getRawType()).isAssignableFrom(type))
Or there may be some better way to handle it, like removing the ResourceMethod.class.getName() request attribute in org.jboss.resteasy.core.SynchronousDispatcher.writeException before calling ServerResponseWriter.writeNomapResponse. In any case something should be done to make sure the type and the generic type don't conflict.