forked from FasterXML/jackson-module-scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression in Map deser, in Scala 2.13 w default typing
This Map serializer is implemented in terms of the Java version and is somewhat fragile, as discussed in FasterXML#643 / FasterXML#470. This commit ensures that the wrapper class is a member class in both Scala and Java. That results in this JSON as the serializer code chooses not to put the inner class name in the type annotation. ``` {"m":["scala.collection.immutable.Map",{"one":"one","two":"two"}]} ``` Fixes FasterXML#643
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...est/scala/com/fasterxml/jackson/module/scala/deser/DefaultTypingMapDeserializerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.fasterxml.jackson.module.scala.deser | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.scala.DefaultScalaModule | ||
|
||
import scala.collection.immutable | ||
|
||
class DefaultTypingMapDeserializerTest extends DeserializerTest { | ||
|
||
def module: DefaultScalaModule.type = DefaultScalaModule | ||
|
||
override def newMapper: ObjectMapper = { | ||
val mapper = super.newMapper | ||
mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator) | ||
} | ||
|
||
"Scala Module" should "deserialize immutable Map when default typing enabled" in { | ||
val map = HasMap(immutable.Map("one" -> "one", "two" -> "two")) | ||
|
||
val mapper = newMapper | ||
|
||
val json = mapper.writeValueAsString(map) | ||
// Was failing in Scala 2.13+ with: | ||
// > Could not resolve type id 'scala.collection.convert.JavaCollectionWrappers$MapWrapper' as a subtype of | ||
// > `scala.collection.immutable.Map<java.lang.String,java.lang.String>`: Not a subtype | ||
// | ||
// prior the changing MapSerializerModule.scala to use an inner class for MapWrapper | ||
val read = mapper.readValue(json, classOf[HasMap]) | ||
|
||
read shouldEqual map | ||
} | ||
|
||
} | ||
|
||
case class HasMap(m: Map[String, String]) |