I wanted to try out scala pickles for an upcoming project which I'm using Dispatch for so I put together a small example using pickles to extract json into case classes. It compiles and works, but I'm not sure if it's ready for prime time. I haven't tested it much or tried to check out the generation code. Anyway, I thought I'd post the example here in case anyone else was interested in pickles.
trait Service {
val port: Option[Int]
val host: String
def service = port.map(p => :/(host, p)).getOrElse(:/(host))
def extract[A : Unpickler : FastTypeTag](json: String) = json.unpickle[A]
def get[A : Unpickler : FastTypeTag](path: String, params: (String, String)*): Future[A] = {
val svc = service / path <<? Seq(params: _*)
HttpHelper.executor(svc OK as.String).map(extract)
}
}
And then to test
case class Foo(bar: String, baz: Baz)
case class Baz(id: Int)