From f11476c6582e60aaa5b24174319b5a62de23c96b Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 25 May 2011 15:56:54 +0200 Subject: Add DelegatingFormat --- src/main/scala/cc/spray/json/AdditionalFormats.scala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/scala/cc') diff --git a/src/main/scala/cc/spray/json/AdditionalFormats.scala b/src/main/scala/cc/spray/json/AdditionalFormats.scala index 62a30e7..5417e5a 100644 --- a/src/main/scala/cc/spray/json/AdditionalFormats.scala +++ b/src/main/scala/cc/spray/json/AdditionalFormats.scala @@ -27,6 +27,11 @@ trait AdditionalFormats { def read(value: JsValue) = value } + class DelegatingFormat[T](delegate: JsonFormat[T]) extends JsonFormat[T] { + def write(obj: T) = delegate.write(obj) + def read(json: JsValue) = delegate.read(json) + } + def formatFromWriter[T :JsonWriter] = new JsonFormat[T] { def write(obj: T) = obj.toJson def read(value: JsValue) = throw new RuntimeException("JsonFormat constructed from JsonWriter can't read from JSON") -- cgit v1.2.3