angularjs - Why is Angular JSON coming in as a ListBuffer? (And how to parse...) -
edit I initially mis-described it - it was written again below.
For some reason, I can not get the angular to send the Jesonon payload in such a way that it is considered as a simple string. Looking at the body, it is always ListBuffer
for any unknown reason.
Code
Application.scala
(Reading is taking [string] and (JSP script \ "language") [int]) ((name ): String, language ID: int) = & gt; User (None, Name, Language Ind)) Submit SubmitUser = Action (BodyPursers.prsegenson) {Insert Request = & gt; Val userResult = request.body.validate [user] userResult.fold (Errors => (BadRequest (Json.obj ("Status" -> "KO", "message" - & gt; J.S.R.R. Tupet Jason ( Errors)))}, user = & gt; {userDao.add (user) is ok (Json.obj ("condition" -> "OK", "message" -> ("user" "+ user .full_name + "'saved'.);)}}}
User.scala
case class user (id: option [int] Full_name: string, language: int)
app.js
(relevant piece only)
$ Scope.submit = function (event)) {$ Scope.loadingTra Cker = promiseTracker (); $ Http.post ('/ user', {data: {name: 'joe blow', language: 1}}, {tracker: $ scope.loadingTracker} Return. Success (function } {Console.log (Created with "success! Id" id;);});}
(I use JSON.stringify
, etc.
Exception
Traditional "reads" gives me this error, or something like this:
Play.api.Application $ $ anon $ 1: execution exception [[JsResultException: JsResultException (Errors: list (but list, (validation error) (error.expected.jsstring, wrappedArray ())))))]] play on Api.application $ class.handleError (app Lication.scala: 293) ~ [play_2.10-2.2.2.jar: 2.2.2] Play.api.DefaultApplication.handleError (application.scala: 399) [play_2.10-2.2.2.jar: 2.2.2 ] At play.core.server.netty.PlayDefaultUpstreamHandler $$ $ $ $ $ $ $ anonfun $ applyOrElse $ 3 .apply (PlayDefaultUpstreamHandler.scala: 261) [play_2.10-2.2.2. If: 2.2.2] play On .core.sververtyty PlayDefaultUpstreamHandler $$ $ $ $ $ $ $ anonfun $ applyOrElse $ 3.apply (PlayDefaultUpstreamHandler.scala: 261) [play_2.10-2.2.2. If: 2.2.2] On Scale. Option.map (option scala: 145) [scala-library-2.10.4.jar: na] .netty.playdef at play.core.server AultUpstreamHandler $$ anonfun $ 2.applyOrElse (PlayDefaultUpstreamHandler.scala: 261) [play_2 .10-2.2.2.jpg: 2.2.2] Reason by: play.api.libs.json.JsResultException: JsResultException (Errors: list (list (validation error (error.expected.jsstring, wrappedArray ())) ))) But play.api.libs.json.JsValue $$ anonfun $ 2.apply (JsValue.scala: 64) ~ [play-json_2.10-2.2 .2.jar: 2.2.2] at play.api. Libs.json.jsValue $$ anonefun $ 2.apply (JsValue.scala: 64) ~ [play-json_2.10-2.2.2jar: 2.2.2] At play.api.libs.json.JsResult $ class Fold (JsResult.scala: 71) ~ [play-json_2.10-2.2.2.jar: 2.2.2] at play.api.libs.json.JsError. Fold (JsResult.scala: 10) ~ [play-json_2.10-2.2.2. If: 2.2.2] at play.api.libs.json.JsValue $ class.as (JsValue.scala: 62) ~ [play -Josson_2.10-2.2.Jear: 2.2.2] Play.aplib.sonson.jsobject.s (JSVLUCI: 164) ~ [Play-JasonOmo.10-2.2.2.jz: 2.2. 2]
Because the data looks like this:
& gt; Body = {play.api.libs.json.JsObject@14793} {"data": {"name": "jhanka", "language": 1}}
and is a member of "jsobject" Field
which is a ListBuffer (in this case, size = 1)
I know that it is completely "noob" question but I do not know how From ListBuilder
, parse it alone in the Case class . I want to parse it exactly what is most appropriate; It does not make sense to me that this is normal J.S. Why is the playbuster changing to ListBuffer?
Any suggestions / ideas?
I'm not sure of your search for data in the right place.
< Code> (jspit \ "name")
I think you are leaving the "data" level in your JSON data structure. You can try adding
(JSP script \ "data \" name \)
and see if things get better Besides, You can try defining your reads directly defining the underlying format of this:
Jason.Format [user]
And then read your data you are already doing:
val placeResult = request.body.validate [user]
These are just some hints , I am a json O I nor scale is not to specialize and I code ...
Comments
Post a Comment