Permalink
Browse files

Add helpers to write in pretty JSON format

  • Loading branch information...
1 parent 102499e commit 560aa5eedcc8bf3ed986582a6db057d95fe3fb09 Joni Freeman committed Nov 16, 2011
Showing with 10 additions and 0 deletions.
  1. +10 −0 core/json/src/main/scala/net/liftweb/json/Serialization.scala
@@ -42,6 +42,16 @@ object Serialization {
def write[A <: AnyRef, W <: Writer](a: A, out: W)(implicit formats: Formats): W =
Printer.compact(render(Extraction.decompose(a)(formats)), out)
+ /** Serialize to String (pretty format).
+ */
+ def writePretty[A <: AnyRef](a: A)(implicit formats: Formats): String =
+ (writePretty(a, new StringWriter)(formats)).toString
+
+ /** Serialize to Writer (pretty format).
+ */
+ def writePretty[A <: AnyRef, W <: Writer](a: A, out: W)(implicit formats: Formats): W =
+ Printer.pretty(render(Extraction.decompose(a)(formats)), out)
+
/** Deserialize from a String.
*/
def read[A](json: String)(implicit formats: Formats, mf: Manifest[A]): A =

0 comments on commit 560aa5e

Please sign in to comment.