jackson-module-scala
jackson-module-scala copied to clipboard
investigate why JsonValue annotation does not work in Scala 3
These tests only pass when Scala 2 is used:
- https://github.com/FasterXML/jackson-module-scala/blob/master/src/test/scala-2.%2B/com/fasterxml/jackson/module/scala/ser/AnyValScala2SerializerTest.scala
- https://github.com/FasterXML/jackson-module-scala/blob/master/src/test/scala-2.%2B/com/fasterxml/jackson/module/scala/ser/JsonValueScala2Test.scala
I was trying to debug the issue with @JsonValue being ignored with scala 3.
The way this works is mostly a mystery to me, but I did notice one difference, using the debugger, when running TestJsonValue with scala 2 vs 3.
I executed this in the debugger "Evaluate expression" tool
classOf[ValueClass].getMethod("value").getDeclaredAnnotations
With scala 2, it returns an array with one item. With scala 3, it returns an empty array.
Not sure how useful this is :)
Thanks @caarmen - that sounds like the likely cause. The Scala3 compiler has a few optimisations that has caused a few issues for jackson.
Could this issue be related? https://github.com/lampepfl/dotty/issues/12492
I've also linked to https://github.com/FasterXML/jackson-databind/issues/3063
Looks like Scala 3.3 fixes this. Tested with https://github.com/FasterXML/jackson-module-scala/tree/scala-3.3
It is likely that jackson-module-scala will not be compiled with Scala 3.3 until maybe the 2.16.0 release but it is likely that using Scala 3.3 runtime should be enough to fix this for users.
Scala 3.3.0 is released. You should be able to use this any recent jackson-module-scala release with Scala 3.3.0. Upgrading to Scala 3.3.0 should be enough. See #635 for the formal uptake of Scala 3.3.0.