diff options
author | Mathias <mathias@spray.cc> | 2011-05-25 15:56:54 +0200 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-05-25 15:56:54 +0200 |
commit | f11476c6582e60aaa5b24174319b5a62de23c96b (patch) | |
tree | 01d3c0e675ef13b451aeab4ee2e40c4f9336875c /src/main/scala/cc | |
parent | d9ee63c346050430f7c52d4d9cb6108809950a36 (diff) | |
download | spray-json-f11476c6582e60aaa5b24174319b5a62de23c96b.tar.gz spray-json-f11476c6582e60aaa5b24174319b5a62de23c96b.tar.bz2 spray-json-f11476c6582e60aaa5b24174319b5a62de23c96b.zip |
Add DelegatingFormat
Diffstat (limited to 'src/main/scala/cc')
-rw-r--r-- | src/main/scala/cc/spray/json/AdditionalFormats.scala | 5 |
1 files changed, 5 insertions, 0 deletions
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") |