Guest User

Test2.scala

a guest
Oct 25th, 2015
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import play.libs.Json
  2.  
  3. class Test2 extends App {
  4.  
  5.     val json = """{
  6.         "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9,
  7.         "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17,
  8.         "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": { "a": 1, "b": 2 }
  9.     }"""
  10.  
  11.     case class Foo(
  12.         a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int, i: Int,
  13.         j: Int, k: Int, l: Int, m: Int, n: Int, o: Int, p: Int, q: Int, r: Int,
  14.         s: Int, t: Int, u: Int, v: Int, w: Option[Bar]
  15.     )
  16.  
  17.     case class Bar(a: Int, b: Int)
  18.  
  19.     import org.cvogt.play.json.Jsonx
  20.     import org.cvogt.play.json.implicits.optionWithNull
  21.     import org.cvogt.play.json.SingletonEncoder.simpleName
  22.     import org.cvogt.play.json.implicits.formatSingleton
  23.  
  24.     implicit val jsonFormat = Jsonx.formatCaseClass[Foo]
  25.  
  26.     val result = Json.parse(json)
  27.  
  28.     val foo = Json.fromJson[Foo](result, classOf[Foo])
  29.  
  30.     println(foo)
  31.  
  32. }
  33.  
  34. /*
  35. [error] Test2.scala:22: could not find implicit value for parameter helper: play.api.libs.json.Reads[Option[Test2.this.Bar]]
  36. [error] TRIGGERED BY: could not find implicit value for parameter helper: org.cvogt.play.json.OptionValidationDispatcher[Option[Test2.this.Bar]]
  37. [error] TO SOLVE THIS
  38. [error] 1. Make sure there is a Reads[Option[Test2.this.Bar]] or Format[Option[Test2.this.Bar]] in the implicit scope
  39. [error] 2. In case of Reads[Option[...]] you need to either
  40. [error]    import org.cvogt.play.json.implicits.optionWithNull // suggested
  41. [error]    or
  42. [error]    import org.cvogt.play.json.implicits.optionNoError // buggy play-json 2.3 behavior
  43. [error] 3. In case of Reads[... .type]
  44. [error]    import org.cvogt.play.json.SingletonEncoder.simpleName
  45. [error]    import org.cvogt.play.json.implicits.formatSingleton
  46. [error]     implicit val jsonFormat = Jsonx.formatCaseClass[Foo]
  47. [error]                                                    ^
  48. [error] one error found
  49. [error] (compile:compileIncremental) Compilation failed
  50. [error] Total time: 3 s, completed 25-Oct-2015 07:13:31
  51. */
RAW Paste Data