diff options
author | Mathias <mathias@spray.io> | 2013-05-13 13:11:14 +0200 |
---|---|---|
committer | Mathias <mathias@spray.io> | 2013-05-13 13:32:19 +0200 |
commit | 8dff7ed4d9635aae3ae17a722fe6f1ea4376a215 (patch) | |
tree | 7bfb8f59f59212849af4d45a671c8875da8cdbd6 | |
parent | 59298d1497dc7d4c412279af3f8809289e72cac6 (diff) | |
download | spray-json-8dff7ed4d9635aae3ae17a722fe6f1ea4376a215.tar.gz spray-json-8dff7ed4d9635aae3ae17a722fe6f1ea4376a215.tar.bz2 spray-json-8dff7ed4d9635aae3ae17a722fe6f1ea4376a215.zip |
Add RootJsonFormats for JsObject and JsArray
-rw-r--r-- | src/main/scala/spray/json/AdditionalFormats.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/scala/spray/json/AdditionalFormats.scala b/src/main/scala/spray/json/AdditionalFormats.scala index cc52f8d..fbabb0b 100644 --- a/src/main/scala/spray/json/AdditionalFormats.scala +++ b/src/main/scala/spray/json/AdditionalFormats.scala @@ -27,6 +27,19 @@ trait AdditionalFormats { def read(value: JsValue) = value } + implicit object RootJsObjectFormat extends RootJsonFormat[JsObject] { + def write(value: JsObject) = value + def read(value: JsValue) = value.asJsObject + } + + implicit object RootJsArrayFormat extends RootJsonFormat[JsArray] { + def write(value: JsArray) = value + def read(value: JsValue) = value match { + case x: JsArray => x + case _ => deserializationError("JSON array expected") + } + } + /** * Constructs a JsonFormat from its two parts, JsonReader and JsonWriter. */ |