Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import play.libs.Json
- class Test2 extends App {
- val json = """{
- "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9,
- "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17,
- "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": { "a": 1, "b": 2 }
- }"""
- case class Foo(
- a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int, i: Int,
- j: Int, k: Int, l: Int, m: Int, n: Int, o: Int, p: Int, q: Int, r: Int,
- s: Int, t: Int, u: Int, v: Int, w: Option[Bar]
- )
- case class Bar(a: Int, b: Int)
- import org.cvogt.play.json.Jsonx
- import org.cvogt.play.json.implicits.optionWithNull
- import org.cvogt.play.json.SingletonEncoder.simpleName
- import org.cvogt.play.json.implicits.formatSingleton
- implicit val jsonFormat = Jsonx.formatCaseClass[Foo]
- val result = Json.parse(json)
- val foo = Json.fromJson[Foo](result, classOf[Foo])
- println(foo)
- }
- /*
- [error] Test2.scala:22: could not find implicit value for parameter helper: play.api.libs.json.Reads[Option[Test2.this.Bar]]
- [error] TRIGGERED BY: could not find implicit value for parameter helper: org.cvogt.play.json.OptionValidationDispatcher[Option[Test2.this.Bar]]
- [error] TO SOLVE THIS
- [error] 1. Make sure there is a Reads[Option[Test2.this.Bar]] or Format[Option[Test2.this.Bar]] in the implicit scope
- [error] 2. In case of Reads[Option[...]] you need to either
- [error] import org.cvogt.play.json.implicits.optionWithNull // suggested
- [error] or
- [error] import org.cvogt.play.json.implicits.optionNoError // buggy play-json 2.3 behavior
- [error] 3. In case of Reads[... .type]
- [error] import org.cvogt.play.json.SingletonEncoder.simpleName
- [error] import org.cvogt.play.json.implicits.formatSingleton
- [error] implicit val jsonFormat = Jsonx.formatCaseClass[Foo]
- [error] ^
- [error] one error found
- [error] (compile:compileIncremental) Compilation failed
- [error] Total time: 3 s, completed 25-Oct-2015 07:13:31
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement