I am trying to parse json in my case class delphormim
case class DealFormMap (range: option [Int], filter option [DealFormFilterMap]) case square DealFormFilterMap (on option [string] code: option [string]) built Val dealFormMapReads: Books [DealFormMap] = ((JsPath \ "border") readNullable [int] and (JsPath \ "filter") readNullable [DealFormFilterMap]) (DealFormMap) Built-in Val dealFormFilterMapReads: ... Reads [DealFormFilterMap] = (JsPath \ "date") readNullable [string]
JSON in question and parsing attempt
val str = "" " {"Limit": 10, "Filter": {"Date": "2014-10-27"}} "" "Val FRM = Jason. PRSE (SR). [Delfermmap]
a Cryptic error which I think causes stack that
play.api.Application $$ $ $ anon $: execution exception [[NullPointerException: null]] to play. API.App $ class.handError (application.scala: 296) ~ [play_2.11-2.3.5. If: 2.3.5] play.api.DefaultApplication.handleError (application.scala: 4 02) [play_2.11- 2.3.5.jar: [play_2.11-2.3.5.jar: 2.3.5] play.core.server.netty.PlayDefaultUpstreamHandler $$ anonfun $ 14 $$ anonfun $ $ 1 applyOrElse (205 PlayDefaultUpstreamHandler.scala) are: scala on 2.3.5]: [play_2.11-2.3.5.jar: 2.3.5] $$ on play.core.server.netty.PlayDefaultUpstreamHandler anonfun $ 14 $$ apply anonfun $ $ 1.applyOrElse (202 PlayDefaultUpstreamHandler.scala) apply .runtime.AbstractPartialFunction.apply (AbstractPartialFunction.scala: 36) [scala-library -2.11.2. jar: na]: java.lang.NullPointerException: due to play .api.libs.json.PathReads Do null ineligible to apply $ 1 $ $ $ $ $ $ $ $ to $$ anonfun $ apply $ $ $ 9apply (JsConstraints.scala: 65) ~ [play-json_2.11-2.3. 5.jar: 2.3.5] at play.api.libs.json. PathReads $$ $ $ Cancel $ 1 $ $ $ $ $ $ $ Apply $ $ $ $ Apply $ 9apply (JsConstraints.scala: 63) ~ [play-json_2.11-2.3.5.jar: 2.3 5] .l Ibs.json.JsResult at play.api $ class.fold (JsResult.scala: 76) ~ [play-json_2.11-2.3.5. If: 2.3.5] at play.api.libs.json .JsSuccess.fold (JSRSalt Scholle): 9) ~ [Play-json_2.11-2.3.5. If: 2.3.5] play.api.libs.json.PathReads $$ at $ $ $ $ 1 $ $ Exclusive $ $ Apply $ .apply (JsConstraints.scala: 61) ~ [play-json_2.11-2.3.5.jar: 2.3.5]
I'm going out of ideas here What can be the problem?
The problem is the initial order dealFormMapReads
underlying dealFormFilterMapReads
Depending on which, which is not defined by then it will be compiled as it is found to be contained, even if it has not been started, therefore the form of dealFormMapReads
as null
, Which ultimately causes the NPE.
Lazily loading will fix it:
Built-in Val dealFormMapReads: .. Reads [DealFormMap] = ((JsPath \ "border") readNullable [Int] and (JsPath \ "filter") lazyReadNullable
or just Can swap the order in which read
is defined.
The NPE is thrown here is similar to this example:
Case class A (i: IT) object test {val test = a.toString val a = A (1)} // compiles throws Test.test // NPE here, because `A` was not started before` Test`
Comments
Post a Comment