com.fasterxml.jackson.databind.JsonMappingException

tip

Specify the order of serializing object field with the @JsonPropertyOrder annotation.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • change master to slave
    via GitHub by wenxueliu
    ,
  • After upgrade from Jersey 2.4 to Jersey 2.5.1, we have problems with resource methods which return collections. For example when invoking the following method: {code:java} @GET @Path("test") public List<Task> test() { throw new javax.ws.rs.WebApplicationException(Response .status(Response.Status.CONFLICT) .entity(new ErrorPayload("a")) .type(MediaType.APPLICATION_JSON_TYPE) .build() ); } {code} JsonMappingException is thrown: {noformat} com.fasterxml.jackson.databind.JsonMappingException: Incompatible types: declared root type ([collection type; class java.util.List, contains [simple type, class com.odesk.editorial.evaluation.to.Task]]) vs com.odesk.editorial.evaluation.to.payloads.ErrorPayload 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 com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:542) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:243) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:230) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149) at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:103) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149) at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:88) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149) at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139) at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:574) at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:381) at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:421) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:265) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:267) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318) {noformat} Expected result: serialized ErrorPayload is JSON format is sent to browser. If I change method definition to {code:java} @GET @Path("test") public Task test() { .... } {code} it works as expected
    via by ymakhno,
    • com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.jgrapht.graph.AbstractBaseGraph$ArrayListFactory and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: org.jgrapht.graph.SimpleDirectedGraph["edgeSetFactory"]) at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69) at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130) at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1387) at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1088) at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:909) at ms.fragment.JSONTreeGenerator.main(JSONTreeGenerator.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

    Users with the same issue

    Axelo
    1 times, last one,
    Unknown visitor2 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    23 more bugmates