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

Inconsistent decomposition of case class with Option of value class #445

Open
mikaelstaldal opened this issue Feb 16, 2017 · 0 comments
Open

Comments

@mikaelstaldal
Copy link

json4s version 3.5.0

scala version 2.11.8

jdk version 1.8.0_45

Code:

import org.json4s.DefaultFormats
import org.json4s.jackson.Serialization

case class Id(id: String) extends AnyVal

case class Data1(id: Id, name: String)

case class Data2(id: Option[Id], name: String)

object Json4sTest {
  implicit val formats = DefaultFormats

  def main(args: Array[String]): Unit = {
    val data1 = Data1(Id("17"), "foo")
    val data2 = Data2(Some(Id("17")), "foo")
    println(s"json 1: ${Serialization.write(data1)}")
    println(s"json 2: ${Serialization.write(data2)}")
  }
}

actual output:

json 1: {"id":"17","name":"foo"}
json 2: {"id":{"id":"17"},"name":"foo"}

expected output:

json 1: {"id":"17","name":"foo"}
json 2: {"id":"17","name":"foo"}

or maybe:

json 1: {"id":{"id":"17"},"name":"foo"}
json 2: {"id":{"id":"17"},"name":"foo"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant