Repository navigation
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Invalid type=INT #526
Copy link
Copy link
Closed
Description
When I use this library with my scala project, below Exception occurs. It seems that it occurs when I try to deserialize a value of BigDecimal serialized by Messagepack.
scalaVersion := "2.13.3"
libraryDependencies ++= Seq(
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.11.1",
"org.msgpack" % "jackson-dataformat-msgpack" % "0.8.20"
)import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import org.msgpack.jackson.dataformat.MessagePackFactory
object Main extends App {
case class Hoge(d: BigDecimal)
val obj = Hoge(BigDecimal(0))
val mapper = new ObjectMapper(new MessagePackFactory) with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
val bytes = mapper.writeValueAsBytes(obj)
val hoge = mapper.readValue[Hoge](bytes)
}Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Invalid type=INT (through reference chain: Main$Hoge["d"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:397)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:356)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1726)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:537)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:419)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1322)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:331)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4482)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3529)
at com.fasterxml.jackson.module.scala.ScalaObjectMapper.readValue(ScalaObjectMapper.scala:203)
at com.fasterxml.jackson.module.scala.ScalaObjectMapper.readValue$(ScalaObjectMapper.scala:202)
at Main$$anon$1.readValue(Main.scala:13)
at Main$.delayedEndpoint$Main$1(Main.scala:21)
at Main$delayedInit$body.apply(Main.scala:7)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:73)
at scala.App.$anonfun$main$1$adapted(App.scala:73)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
at scala.collection.AbstractIterable.foreach(Iterable.scala:920)
at scala.App.main(App.scala:73)
at scala.App.main$(App.scala:71)
at Main$.main(Main.scala:7)
at Main.main(Main.scala)
Caused by: java.lang.IllegalStateException: Invalid type=INT
at org.msgpack.jackson.dataformat.MessagePackParser.getText(MessagePackParser.java:387)
at com.fasterxml.jackson.module.scala.deser.BigNumberDeserializer.deserialize(ScalaNumberDeserializersModule.scala:20)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:542)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:535)
... 23 moreI have already found that the workaround is to fix getText in MessagePackParser.java(msgpack/msgpack-java) like below.
cozima0210@d11ecc5
But I know that there is another workaround to solve it. It is to fix deserialize in ScalaNumberDeserializersModule.scala(FasterXML/jackson-module-scala) like below.
cozima0210/jackson-module-scala@a6f7420
Therefore, I want to hear you which repositories I should send PR. Thanks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
cozima0210 commentedon Jul 28, 2020
I also send a same issue to https://github.com/FasterXML/jackson-module-scala/.
komamitsu commentedon Aug 3, 2020
I tried to reproduce this issue in Java, but I couldn't. Is there any way to reproduce this issue without jackson-module-scala?
cozima0210 commentedon Aug 4, 2020
@komamitsu Thanks for your reply. No, it isn't. If you tried to reproduce it with
java.math.BigDecimal, please confirm this issue withscala.math.BigDecimal. Currently I don't understand which repository should be fixed to resolve this error.pjfanning commentedon Aug 4, 2020
@komamitsu the fix in cozima0210@d11ecc5 is to allow getText to work for numbers. It is not not uncommon for users to encode numbers as JSON strings because many JSON libs assume JSON numbers are doubles and double are only an approximation of the actual number - while in text you can provide the number with arbitrary precision.
ktholen commentedon Sep 11, 2020
@komamitsu @pjfanning would it be possible to cut a new release? We just ran into this problem today and would like to use the new version in our application.
komamitsu commentedon Sep 12, 2020
@ktholen Released 0.8.21 that includes this fix.
ktholen commentedon Sep 15, 2020
Thank you! Works as expected!