Json.format doesn't work as documented

45 views
Skip to first unread message

Jim Newsham

unread,
Feb 3, 2015, 3:25:18 PM2/3/15
to raptur...@googlegroups.com

Hi,

I'm just starting off using rapture-json.  Pretty nice so far. I just wanted to report that formatting is not working as documented at https://github.com/propensive/rapture-json, although I was able to figure out how to get it to work.  See the below example.

import rapture.json._
import rapture.json.jsonBackends.json4s._

object RaptureFormatting extends App {

  val j = json"""[{ "name": "catcher in the rye"}, {"name": "lord of the flies"}]"""

  // this doesn't compile
  //import formatters.humanReadable
  //println(Json.format(j))

  // this doesn't compile
  //println(Json.format(j)(formatters.humanReadable))
  
  // this compiles/works
  println(Json.format(j)(formatters.humanReadable()))
  
}

Regards,
Jim

Jon Pretty

unread,
Feb 4, 2015, 3:07:32 AM2/4/15
to raptur...@googlegroups.com
Thanks for pointing this out, Jim!

It's a documentation issue with something that changed in the most recent release. I've corrected the README file now, but the difference is that you need to import either `humanReadable._` or `compact._`. I.e. everything from inside those objects.

You discovered the "alternative" approach, which is to use the `apply()` method, though I'm not going to document this yet, as I'm not sure it will stay.

The reason I changed from importing `humanReadable` to `humanReadable._` is that it allows me to give the implicit formatters inside `humanReadable` and `compact` identical names. This means that if you import one, then subsequently import the other, the last one shadows the former, which means you can switch just by importing "over" the previous one. Previously, you could import both, and get an ambiguous implicits error when both were in scope at the same time.

Hope everything else is making sense!

Cheers,
Jon

--
You received this message because you are subscribed to the Google Groups "Rapture users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapture-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jon Pretty | @propensive
Reply all
Reply to author
Forward
0 new messages