Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add helpers to write in pretty JSON format

  • Loading branch information...
commit 560aa5eedcc8bf3ed986582a6db057d95fe3fb09 1 parent 102499e
Joni Freeman authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 core/json/src/main/scala/net/liftweb/json/Serialization.scala
View
10 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 =
Please sign in to comment.
Something went wrong with that request. Please try again.