jackson-module-scala icon indicating copy to clipboard operation
jackson-module-scala copied to clipboard

investigate why JsonValue annotation does not work in Scala 3

Open pjfanning opened this issue 4 years ago • 4 comments

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

pjfanning avatar Jul 31 '21 19:07 pjfanning

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 :)

caarmen avatar Dec 04 '21 19:12 caarmen

Thanks @caarmen - that sounds like the likely cause. The Scala3 compiler has a few optimisations that has caused a few issues for jackson.

pjfanning avatar Dec 04 '21 20:12 pjfanning

Could this issue be related? https://github.com/lampepfl/dotty/issues/12492

caarmen avatar Dec 04 '21 21:12 caarmen

I've also linked to https://github.com/FasterXML/jackson-databind/issues/3063

pjfanning avatar Dec 05 '21 13:12 pjfanning

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.

pjfanning avatar Mar 11 '23 12:03 pjfanning

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.

pjfanning avatar May 23 '23 20:05 pjfanning