diff options
author | Mathias <mathias@spray.cc> | 2011-12-07 10:38:29 +0100 |
---|---|---|
committer | Mathias <mathias@spray.cc> | 2011-12-07 10:38:29 +0100 |
commit | 6a5ccb2e6c37f7922db34f29c1f9cfd61a2397e8 (patch) | |
tree | 5b58cf9463bf300e92f6eedb5042f5e4c5b6e93a /src/main/scala/cc/spray/json/CollectionFormats.scala | |
parent | fd80c9099d4d474a6080df11a5786bd7e9b5cb7f (diff) | |
download | spray-json-6a5ccb2e6c37f7922db34f29c1f9cfd61a2397e8.tar.gz spray-json-6a5ccb2e6c37f7922db34f29c1f9cfd61a2397e8.tar.bz2 spray-json-6a5ccb2e6c37f7922db34f29c1f9cfd61a2397e8.zip |
Move exception into package.scala, simplify throwing of (De)SerializationExceptions
Diffstat (limited to 'src/main/scala/cc/spray/json/CollectionFormats.scala')
-rw-r--r-- | src/main/scala/cc/spray/json/CollectionFormats.scala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main/scala/cc/spray/json/CollectionFormats.scala b/src/main/scala/cc/spray/json/CollectionFormats.scala index c6c3403..93e41ab 100644 --- a/src/main/scala/cc/spray/json/CollectionFormats.scala +++ b/src/main/scala/cc/spray/json/CollectionFormats.scala @@ -26,7 +26,7 @@ trait CollectionFormats { def write(list: List[T]) = JsArray(list.map(_.toJson)) def read(value: JsValue) = value match { case JsArray(elements) => elements.map(_.convertTo[T]) - case x => throw new DeserializationException("Expected List as JsArray, but got " + x) + case x => deserializationError("Expected List as JsArray, but got " + x) } } @@ -37,7 +37,7 @@ trait CollectionFormats { def write(array: Array[T]) = JsArray(array.map(_.toJson).toList) def read(value: JsValue) = value match { case JsArray(elements) => elements.map(_.convertTo[T]).toArray[T] - case x => throw new DeserializationException("Expected Array as JsArray, but got " + x) + case x => deserializationError("Expected Array as JsArray, but got " + x) } } @@ -55,9 +55,10 @@ trait CollectionFormats { } } def read(value: JsValue) = value match { - case JsObject(fields) => - fields.map(field => (JsString(field._1).convertTo[K], field._2.convertTo[V])) (collection.breakOut) - case x => throw new DeserializationException("Expected Map as JsObject, but got " + x) + case x: JsObject => x.fields.map { field => + (JsString(field._1).convertTo[K], field._2.convertTo[V]) + } (collection.breakOut) + case x => deserializationError("Expected Map as JsObject, but got " + x) } } @@ -86,7 +87,7 @@ trait CollectionFormats { def write(iterable: I) = JsArray(iterable.map(_.toJson).toList) def read(value: JsValue) = value match { case JsArray(elements) => f(elements.map(_.convertTo[T])) - case x => throw new DeserializationException("Expected Collection as JsArray, but got " + x) + case x => deserializationError("Expected Collection as JsArray, but got " + x) } } |