On Fri, Jul 24, 2009 at 8:57 PM, fbettag <[email protected]> wrote: > > Still one problem when parsing: > > results: {"name":"New Content","language":"en","content":"","layout": > 22} > > java.lang.NumberFormatException: For input string: "22.0" > at java.lang.NumberFormatException.forInputString > (NumberFormatException.java:48) > at java.lang.Long.parseLong(Long.java:412) > at java.lang.Long.parseLong(Long.java:461) > at scala.runtime.RichString.toLong(RichString.scala:214) > > > > def addOrUpdateContent(inContentid: String): LiftResponse = { > val obj = Content.find(By(Content.id, inContentid.toLong)) > openOr > new Content > > JSONParser.parse(S.params("results").first) match { > case Full(res: Map[String, String]) => { > try { > obj.name(res.getOrElse("name", > obj.name).toString) > > .content(res.getOrElse("content", obj.content).toString) > > .language(res.getOrElse("language", obj.language).toString) > > .layout(res.getOrElse("layout", obj.layout).toString.toLong) > > .content(res.getOrElse("content", obj.content).toString) > .save > JsonResponse(JsObj("result" > -> obj.asJs)) > } catch { > case e => { > > Log.error("Could not save content", e) > > InternalServerErrorResponse() > } > } > } > case _ => BadResponse() > } > } > > any ideas? the POST content is right, the parsing is b0rkst > somewhere :s
The issue is that you're converting a Number (which is probably a Double) into a String and then parsing it as a Long and the Long parser is getting confused by the "." in the toString'ed Double. I'd suggest writing a bit of code that uses Box'es/Option's and implicits to help you unpack the object in a type-safe manner. There are already some examples in this thread. If you need more examples or more concrete code, please let us know. > > > On 17 Jul., 08:59, Jeppe Nejsum Madsen <[email protected]> wrote: > > David Pollak <[email protected]> writes: > > > You can use: > > > Box.asA[Map[String, _]](in) which will return Full(in) if in is a > > > Map[String, _] or Empty if it's not. This helps in for comprehensions. > > > > Ah, didn't know that. Very nice! > > > > /Jeppe > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
