You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jackson Scala 3 support that uses scala3-reflection
to get type info based on Scala 3 Tasty files
(or at compile time, see Performance section).
The problem that this lib solves in described in this FAQ entry.
The lib can also auto-discover subtypes if you are using Jackson's polymorphism support (@JsonTypeInfo annotation). You can omit the @JsonSubTypes if you dealing with sealed traits.
importcom.fasterxml.jackson.databind.json.JsonMapperimportcom.fasterxml.jackson.module.scala.DefaultScalaModuleimportcom.github.pjfanning.jackson.reflection.ScalaReflectionExtensionsvalmapperBuilder=JsonMapper.builder()
.addModule(DefaultScalaModule)
valmapper= mapperBuilder.build() ::ScalaReflectionExtensions// this should also work but Jackson is moving to supporting only creating mapper instances from a buildervalmapper2=newObjectMapperwithScalaReflectionExtensions
mapper2.registerModule(DefaultScalaModule)
valinstance= mapper.readValue[MyClass](jsonText)
Performance
The code to calculate the class details can be slow, as detailed in gzoller/scala-reflection.
The results are cached, so they won't be recalculated every time you call readValue.
If performance worries you then you should consider enabling the compiler plugin.