Last active
October 5, 2016 06:00
-
-
Save optician/bc84be89557e9a0e93baeddba0b5e7e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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