Skip to content

Commit

Permalink
ArraySeq deserialization issue (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Aug 5, 2022
1 parent dd0bb27 commit 9efbe43
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ trait SeqDeserializerModule extends ScalaTypeModifierModule {

val tagFactories: Iterable[(Class[_], TagFactory)] = Seq(
(classOf[mutable.ArraySeq[_]], mutable.ArraySeq),
(classOf[immutable.ArraySeq[_]], immutable.ArraySeq),
(classOf[mutable.UnrolledBuffer[_]], mutable.UnrolledBuffer)
)

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

import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule}

import java.nio.charset.StandardCharsets
import scala.collection.immutable
import scala.collection.mutable

class ArraySeqSerializerTest extends DeserializerTest {

lazy val module: JacksonModule = DefaultScalaModule
val arraySize = 1000
val obj = (1 to arraySize).map(i => ((i * 1498724053) & 0x1) == 0).toArray
val jsonString = obj.mkString("[", ",", "]")
val jsonBytes = jsonString.getBytes(StandardCharsets.UTF_8)

"An ObjectMapper with the SeqDeserializer" should "handle immutable ArraySeq of booleans" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
val seq = mapper.readValue(jsonBytes, new TypeReference[immutable.ArraySeq[Boolean]] {})
seq should have size arraySize
}

it should "handle mutable ArraySeq of booleans" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
val seq = mapper.readValue(jsonBytes, new TypeReference[mutable.ArraySeq[Boolean]] {})
seq should have size arraySize
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fasterxml.jackson.module.scala.deser

import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule}

import java.nio.charset.StandardCharsets
import scala.collection.immutable
import scala.collection.mutable

class ArraySeqSerializerTest extends DeserializerTest {

lazy val module: JacksonModule = DefaultScalaModule
val arraySize = 1000
val obj = (1 to arraySize).map(i => ((i * 1498724053) & 0x1) == 0).toArray
val jsonString = obj.mkString("[", ",", "]")
val jsonBytes = jsonString.getBytes(StandardCharsets.UTF_8)

"An ObjectMapper with the SeqDeserializer" should "handle immutable ArraySeq of booleans" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
val seq = mapper.readValue(jsonBytes, new TypeReference[immutable.ArraySeq[Boolean]] {})
seq should have size arraySize
}

it should "handle mutable ArraySeq of booleans" in {
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()
val seq = mapper.readValue(jsonBytes, new TypeReference[mutable.ArraySeq[Boolean]] {})
seq should have size arraySize
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fasterxml.jackson.module.scala.deser

import java.util.UUID
import com.fasterxml.jackson.annotation.{JsonSetter, Nulls}
import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
Expand All @@ -9,6 +8,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospector
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule}

import java.util.UUID
import scala.collection.{immutable, mutable}

object SeqDeserializerTest {
Expand Down

0 comments on commit 9efbe43

Please sign in to comment.