FasterXML / FasterXML/jackson-module-scala
objects and case objects not serialized properly on Scala 2.13/3 when getter visibilty is disabled
- Dominant language
- Scala
- Stars
- 506
- Forks
- 138
- Avg merge
- 3h 6m
- Merged PRs (30d)
- 48
Description
This issue is very similar to this: https://github.com/FasterXML/jackson-module-scala/issues/429
Serialization is incorrect when using Scala 2.13 to serialize objects and case objects _that do not belong to the same class as the method that is calling them_.
Here's a minimum working example for this issue:
```scala
case object Foo {
val field: String = "bar"
}
object Main {
def main(args: Array[String]): Unit = {
val mapper = JsonMapper.builder()
.addModule(DefaultScalaModule)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE) // This is the setting that didn't cause issues on Scala 2.12, but does on 2.13
.build()
val output = mapper.writeValueAsString(Foo)
println(output) // prints {} on Scala 2.13, {"field": "bar"} on Scala 2.12
}
}
```
May be worth noting that in the case below, where the object belongs to the same class as the method that is calling it, the serialization works as expected (which was exactly the case described by https://github.com/FasterXML/jackson-module-scala/issues/429):
```scala
class Main {
case object Foo {
val field: String = "bar"
}
def test(): Unit = {
val mapper = JsonMapper.builder()
.addModule(DefaultScalaModule)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
.build()
val output = mapper.writeValueAsString(Foo)
println(output) // Prints {"field":"bar"}
}
}
object Main {
def main(args: Array[String]): Unit = {
new Main().test();
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.