Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-937

Method that returns a list of object throw com.fasterxml.jackson.databind.JsonMappingException: Incompatible types: declared root type exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.4.Final
    • 3.0.2.Final
    • jaxrs
    • None

      I have the following method:
      @GET
      @Path("/")
      @Produces(

      {"application/json"}

      )
      public List<PolicyDto> getPolicies(@Valid @BeanParam PolicyQueryDto queryDto);

      If the validation of queryDto fail, it will throw a ValidationException.
      And the same time, resteasy throw the following exception:

      com.fasterxml.jackson.databind.JsonMappingException: Incompatible types: declared root type ([collection type; class java.util.List, contains [simple type, class com.ebao.zhongan.resource.dto.PolicyDto]]) vs com.ebao.rest.common.ExceptionDto
      at com.fasterxml.jackson.databind.SerializerProvider._reportIncompatibleRootType(SerializerProvider.java:790)
      at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:208)
      at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:496)
      at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.writeTo(ResteasyJackson2Provider.java:186)
      at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:129)
      at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:62)
      at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:118)
      at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
      at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122)
      at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:108)
      at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:153)

      If the return type of method is not a collection, everything is okay.

            rsigal@redhat.com Ronald Sigal
            ozhou_jira Oliver Zhou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: