Hi,
Yes, that's a way to convert JSON AST to string and vice versa. All
functions in lift-json operate on AST instances. This is lets us post-
and pre-process JSON in many ways before converting it to string. See
for instance functions map, merge, diff, \, etc. defined in JsonAST
(scaladocs still missing but will be provided before Lift 2.0 is
released). Typical conversions might for instance remove some data
from JSON, convert data types, change structure of resulting JSON and
so on.
I usually import all needed objects and their members. After that the
code becomes a bit more concise (the cast is unfortunately needed
since JSON comes from the wild and can be anything):
def encodeAsJsonString(in: A) = compact(render(encodeAsJson(in)))
def buildFromJsonString(json: String): A = buildFromJson(parse
(json).asInstanceOf[JObject])
Cheers Joni
On 16 joulu, 09:03, Xuefeng Wu <
ben...@gmail.com> wrote:
> Hi,
> I add two method to en/decode JObject/String
>
> def encodeAsJsonString(in: A): String =
> Printer.compact(JsonAST.render(encodeAsJson(in)))
> def buildFromJsonString(json: String): A =
> buildFromJson(JsonParser.parse(json).asInstanceOf[JsonAST.JObject])
>
> Do there have better way?
>
> On Thu, Dec 3, 2009 at 5:15 AM, David Pollak
> <
feeder.of.the.be...@gmail.com>wrote:
> > Beginning Scalahttp://
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
lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> >
liftweb+u...@googlegroups.com<
liftweb%2Bunsu...@googlegroups.com>
> > .