Skip to content

include ScalaObjectDeserializerModule in DefaultScalaModule #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ val mapper = JsonMapper.builder()

One Scala module that isn't part of `DefaultScalaModule` is `ScalaObjectDeserializerModule`. This module is used to
ensure that deserialization to a Scala object does not create a new instance of the object.
This latter module is not yet included in `DefaultScalaModule` for backward compatibility reasons.
It is included in the v3.0.0, which is still under development.
This latter module is not yet included in `DefaultScalaModule` but will be included in v2.16.0.
It is already included in v3.0.0, which is still under development.

## DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.fasterxml.jackson.module.scala

import com.fasterxml.jackson.module.scala.deser.{ScalaNumberDeserializersModule, UntypedObjectDeserializerModule}
import com.fasterxml.jackson.module.scala.deser.{
ScalaNumberDeserializersModule,
ScalaObjectDeserializerModule,
UntypedObjectDeserializerModule
}
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospectorModule

/**
Expand All @@ -25,6 +29,7 @@ class DefaultScalaModule
with MapModule
with SetModule
with ScalaNumberDeserializersModule
with ScalaObjectDeserializerModule
with ScalaAnnotationIntrospectorModule
with UntypedObjectDeserializerModule
with EitherModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.{JsonAutoDetect, PropertyAccessor}
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import com.fasterxml.jackson.module.scala.deser.CaseObjectDeserializerTest.{Foo, TestObject}
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospectorModule

object CaseObjectDeserializerTest {
case object TestObject
Expand All @@ -13,12 +14,11 @@ object CaseObjectDeserializerTest {
}
}

//see also CaseObjectScala2DeserializerTest
class CaseObjectDeserializerTest extends DeserializerTest {
def module = DefaultScalaModule

"An ObjectMapper with DefaultScalaModule and ScalaObjectDeserializerModule" should "deserialize a case object and not create a new instance" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).addModule(ScalaObjectDeserializerModule).build()
"An ObjectMapper with DefaultScalaModule" should "deserialize a case object and not create a new instance" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
val original = TestObject
val json = mapper.writeValueAsString(original)
val deserialized = mapper.readValue(json, TestObject.getClass)
Expand All @@ -36,7 +36,6 @@ class CaseObjectDeserializerTest extends DeserializerTest {
it should "deserialize Foo and not create a new instance (visibility settings)" in {
val mapper = JsonMapper.builder()
.addModule(DefaultScalaModule)
.addModule(ScalaObjectDeserializerModule)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
.build()
Expand All @@ -46,19 +45,18 @@ class CaseObjectDeserializerTest extends DeserializerTest {
assert(deserialized == original)
}

"An ObjectMapper with ClassTagExtensions and ScalaObjectDeserializerModule" should "deserialize a case object and not create a new instance" in {
"An ObjectMapper with ClassTagExtensions and DefaultScalaModule" should "deserialize a case object and not create a new instance" in {
val mapper = JsonMapper.builder()
.addModule(DefaultScalaModule)
.addModule(ScalaObjectDeserializerModule)
.build() :: ClassTagExtensions
val original = TestObject
val json = mapper.writeValueAsString(original)
val deserialized = mapper.readValue[TestObject.type](json)
assert(deserialized == original)
}

"An ObjectMapper with DefaultScalaModule but not ScalaObjectDeserializerModule" should "deserialize a case object but create a new instance" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
"An ObjectMapper without ScalaObjectDeserializerModule" should "deserialize a case object but create a new instance" in {
val mapper = JsonMapper.builder().addModule(ScalaAnnotationIntrospectorModule).build()
val original = TestObject
val json = mapper.writeValueAsString(original)
val deserialized = mapper.readValue(json, TestObject.getClass)
Expand Down