On Tue, Oct 27, 2009 at 9:05 AM, GA <[email protected]> wrote: > > Hello guys, > > I have a small Lift API that has to receive JSON content. The content- > type is specified as "application/json". The API method is written as > follows: > > def jsonTest(req: Req): LiftResponse = { > > implicit val formats = net.liftweb.json.DefaultFormats // > Brings in default date formats etc. > case class Person(name: String, password: String) > val json = parse(req.body.toString) /* Line that fails */ > val person = json.extract[Person] > CreatedResponse(wrapXmlBody(<operation id="jsonTest" > success="true"> </operation>), "application/json") > } > > > I want to parse the content using the net.liftweb.jsonParser but the > server returns HTTP 500 error. >
req.body is an Array[Byte]. calling .toString on it will not yield a String representing the Array[Byte]. Try parse(new String(req.body, "UTF-8")) If this doesn't work, please include the stack trace. > > If the content-type is text/xml, the message comes inside of req.xml, > where does it come when it is application/json? > > Thanks in advance, > > GA > > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
