Image Image Image Image Image
Scroll to Top

To Top

Uncategorized

27

Jun
2011

One Comment

In Uncategorized

By admin

lift-json serialization pretty printing

On 27, Jun 2011 | One Comment | In Uncategorized | By admin

The built-in serialization of lift-json prints a string with no newlines. I prefer to have a nicely printed string so that I can edit the file if I want. For this end I created a new function

writePretty

:

object JsonPimps {

  def writePretty[A <: AnyRef](a: A)(implicit formats: Formats): String =
    (writePretty(a, new StringWriter)(formats)).toString

  def writePretty[A <: AnyRef, W <: Writer](a: A, out: W)(implicit formats: Formats): W =
    Printer.pretty(render(Extraction.decompose(a)(formats)), out)
}

Comments

  1. Andrea

    useful, thanks!

Submit a Comment