Skip to content

Instantly share code, notes, and snippets.

@optician
Last active October 5, 2016 06:00
Show Gist options
  • Save optician/bc84be89557e9a0e93baeddba0b5e7e6 to your computer and use it in GitHub Desktop.
Save optician/bc84be89557e9a0e93baeddba0b5e7e6 to your computer and use it in GitHub Desktop.
import pushka.json._
import pushka.annotation._
// First case.
// Simple as is.
@pushka
case class A(subModel: B, i: Int, str: String)
@pushka
case class B(field1: Int, field2: List[Int])
val jsonStr1 =
"""{
|"subModel": {"field1": 10, "field2": [2,3,4,5,6,6,7]},
|"i": 5,
|"str": "some string value"
|}""".stripMargin
val result1 = read[A](jsonStr1)
// Second case.
// You should rename 'subModel' field in json when you are working with sealed trait. =(
@pushka
case class C(subModel: D, i: Int, str: String)
@pushka
sealed trait D
object D {
case class D1(field1: Int, field2: List[Int]) extends D
}
val jsonStr2 =
"""{
|"d1": {"field1": 10, "field2": [2,3,4,5,6,6,7]},
|"i": 5,
|"str": "some string value"
|}""".stripMargin
val result2 = read[D](jsonStr2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment