diff options
author | Mathias <mathias@spray.cc> | 2011-05-25 16:32:22 +0200 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-05-25 16:32:22 +0200 |
commit | 8297c7ae6f1a46df5887e7f3f1d23566b4bd1163 (patch) | |
tree | c4210f452ed79a982893497f7630557897734a75 /src/main/scala/cc/spray/json/JsonFormat.scala | |
parent | f11476c6582e60aaa5b24174319b5a62de23c96b (diff) | |
download | spray-json-8297c7ae6f1a46df5887e7f3f1d23566b4bd1163.tar.gz spray-json-8297c7ae6f1a46df5887e7f3f1d23566b4bd1163.tar.bz2 spray-json-8297c7ae6f1a46df5887e7f3f1d23566b4bd1163.zip |
Add helper function constructing a jsonFormat from Readers and Writer, implicit conversions from functions
Diffstat (limited to 'src/main/scala/cc/spray/json/JsonFormat.scala')
-rw-r--r-- | src/main/scala/cc/spray/json/JsonFormat.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/scala/cc/spray/json/JsonFormat.scala b/src/main/scala/cc/spray/json/JsonFormat.scala index 94a2576..0fedd3f 100644 --- a/src/main/scala/cc/spray/json/JsonFormat.scala +++ b/src/main/scala/cc/spray/json/JsonFormat.scala @@ -24,6 +24,12 @@ trait JsonReader[T] { def read(json: JsValue): T } +object JsonReader { + implicit def func2Reader[T](f: JsValue => T): JsonReader[T] = new JsonReader[T] { + def read(json: JsValue) = f(json) + } +} + /** * Provides the JSON serialization for type T. */ @@ -31,6 +37,12 @@ trait JsonWriter[T] { def write(obj: T): JsValue } +object JsonWriter { + implicit def func2Writer[T](f: T => JsValue): JsonWriter[T] = new JsonWriter[T] { + def write(obj: T) = f(obj) + } +} + /** * Provides the JSON deserialization and serialization for type T. */ |