Skip to content
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

Support new jackson feature @JsonMerge #370

Closed
deblockt opened this issue Apr 18, 2018 · 2 comments
Closed

Support new jackson feature @JsonMerge #370

deblockt opened this issue Apr 18, 2018 · 2 comments
Labels

Comments

@deblockt
Copy link

I have test @JsonMerge on a scala Map.
The merge doesn't work.
did you work on a merge support?

@nbauernfeind
Copy link
Member

Can you provide a code snippet, describe what happens and what you expect to happen?

Thanks!

@deblockt
Copy link
Author

deblockt commented Jul 1, 2018

I have write a code sample who perform same action with Scala Map and Java Map to show differences.

import java.util

import com.fasterxml.jackson.annotation.JsonMerge
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

import scala.collection.mutable
import scala.collection.JavaConverters._

object Main extends App {

  class MergeJavaTest(inputMap: java.util.Map[String, String]) {
    @JsonMerge var map: java.util.Map[String, String] = inputMap
  }

  class MergeScalaTest(inputMap: mutable.Map[String, String]) {
    @JsonMerge var map: mutable.Map[String, String] = inputMap
  }

  val inputTest =
    """
      |{
      | "map": {
      |   "foo": "test"
      | }
      |}
    """.stripMargin

  val map = mutable.Map("bar" -> "test")
  val existingJavaMap = new MergeJavaTest(map.asJava)
  val existingScalaMap = new MergeScalaTest(map)

  val objectMapper = new ObjectMapper().registerModule(DefaultScalaModule)

  val updatedJavaMap: MergeJavaTest = objectMapper.readerForUpdating(existingJavaMap).readValue(inputTest)
  val updatedScalaMap: MergeScalaTest = objectMapper.readerForUpdating(existingScalaMap).readValue(inputTest)

  println(existingJavaMap.map) // {foo=test, bar=test}
  println(existingScalaMap.map) // Map(foo -> test) expected Map(foo -> test, bar -> test)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants