FasterXML / FasterXML/jackson-module-scala

Collection of case classes deserialized as Collection of Map2

Open
#650 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
506
Forks
138
Avg merge
3h 6m
Merged PRs (30d)
48

Description

```scala
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.databind.json.{JsonMapper}

case class B(a: String, b: String)

val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build()

mapper.writeValueAsString(B("a", "b"))
// "{\"a\":\"a\",\"b\":\"b\"}"

val s = mapper.writeValueAsString(List(B("a", "b"), B("c", "d")))
// "[{\"a\":\"a\",\"b\":\"b\"},{\"a\":\"c\",\"b\":\"d\"}]"

mapper.readValue(s, classOf[List[B]])
// List(Map("a" -> "a", "b" -> "b"), Map("a" -> "c", "b" -> "d"))
```

Any attempt to use the values throws a cast error. Unable to cast Map2 to B.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.