com.fasterxml.jackson.databind.JsonMappingException: api.Json cannot be cast to java.lang.String (through reference chain: api.Data["json"])

Stack Overflow | devshorts | 5 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    Serializing/Deserailizing Option of anyval with jackson

    Stack Overflow | 5 months ago | devshorts
    com.fasterxml.jackson.databind.JsonMappingException: api.Json cannot be cast to java.lang.String (through reference chain: api.Data["json"])

    Root Cause Analysis

    1. java.lang.ClassCastException

      api.Json cannot be cast to java.lang.String

      at com.fasterxml.jackson.databind.ser.std.StringSerializer.serialize()
    2. Jackson
      StringSerializer.serialize
      1. com.fasterxml.jackson.databind.ser.std.StringSerializer.serialize(StringSerializer.java:49)[jackson-databind-2.7.5.jar:2.7.5]
      1 frame
    3. jackson-module-scala
      OptionSerializer.serialize
      1. com.fasterxml.jackson.module.scala.ser.OptionSerializer.serialize(OptionSerializerModule.scala:145)[jackson-module-scala_2.10-2.7.5.jar:na]
      2. com.fasterxml.jackson.module.scala.ser.OptionSerializer.serialize(OptionSerializerModule.scala:60)[jackson-module-scala_2.10-2.7.5.jar:na]
      2 frames
    4. Jackson
      ObjectWriter.writeValue
      1. com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:672)[jackson-databind-2.7.5.jar:2.7.5]
      2. com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:678)[jackson-databind-2.7.5.jar:2.7.5]
      3. com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:378)[jackson-databind-2.7.5.jar:2.7.5]
      4. com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:338)[jackson-databind-2.7.5.jar:2.7.5]
      5. com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:342)[jackson-databind-2.7.5.jar:2.7.5]
      6. com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:686)[jackson-databind-2.7.5.jar:2.7.5]
      7. com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)[jackson-databind-2.7.5.jar:2.7.5]
      8. com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130)[jackson-databind-2.7.5.jar:2.7.5]
      9. com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1428)[jackson-databind-2.7.5.jar:2.7.5]
      10. com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:930)[jackson-databind-2.7.5.jar:2.7.5]
      10 frames
    5. Jackson-JAXRS-base
      ProviderBase.writeTo
      1. com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:635)[jackson-jaxrs-base-2.6.3.jar:2.6.3]
      1 frame
    6. Jersey Core
      WriterInterceptorExecutor.proceed
      1. org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)[jersey-common-2.23.2.jar:na]
      2. org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)[jersey-common-2.23.2.jar:na]
      3. org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)[jersey-common-2.23.2.jar:na]
      3 frames
    7. jersey-core-server
      JsonWithPaddingInterceptor.aroundWriteTo
      1. org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)[jersey-server-2.23.2.jar:na]
      1 frame
    8. Jersey Core
      WriterInterceptorExecutor.proceed
      1. org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)[jersey-common-2.23.2.jar:na]
      1 frame
    9. jersey-core-server
      MappableExceptionWrapperInterceptor.aroundWriteTo
      1. org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)[jersey-server-2.23.2.jar:na]
      1 frame