diff options
author | Dan Checkoway <dcheckoway@gmail.com> | 2015-04-25 10:52:31 -0400 |
---|---|---|
committer | Dan Checkoway <dcheckoway@gmail.com> | 2015-04-27 07:25:49 -0400 |
commit | 4a6263779219fe498039b60fceefddfa4f1ba2a3 (patch) | |
tree | ac558972916ac38958ddcb0a6d07be575f46d0af /src/main/scala/spray | |
parent | f56576932f98227ef1bd37981a46562d053f8409 (diff) | |
download | spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.tar.gz spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.tar.bz2 spray-json-4a6263779219fe498039b60fceefddfa4f1ba2a3.zip |
Expose fieldName when able in deserialization errors
Diffstat (limited to 'src/main/scala/spray')
-rw-r--r-- | src/main/scala/spray/json/ProductFormats.scala | 6 | ||||
-rw-r--r-- | src/main/scala/spray/json/package.scala | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/main/scala/spray/json/ProductFormats.scala b/src/main/scala/spray/json/ProductFormats.scala index 9914b55..9e494ff 100644 --- a/src/main/scala/spray/json/ProductFormats.scala +++ b/src/main/scala/spray/json/ProductFormats.scala @@ -56,9 +56,11 @@ trait ProductFormats extends ProductFormatsInstances { try reader.read(x.fields(fieldName)) catch { case e: NoSuchElementException => - deserializationError("Object is missing required member '" + fieldName + "'", e) + deserializationError("Object is missing required member '" + fieldName + "'", e, fieldName :: Nil) + case DeserializationException(msg, cause, fieldNames) => + deserializationError(msg, cause, fieldName :: fieldNames) } - case _ => deserializationError("Object expected in field '" + fieldName + "'") + case _ => deserializationError("Object expected in field '" + fieldName + "'", fieldNames = fieldName :: Nil) } protected def extractFieldNames(classManifest: ClassManifest[_]): Array[String] = { diff --git a/src/main/scala/spray/json/package.scala b/src/main/scala/spray/json/package.scala index fe37c8b..f79b99e 100644 --- a/src/main/scala/spray/json/package.scala +++ b/src/main/scala/spray/json/package.scala @@ -20,7 +20,7 @@ package object json { type JsField = (String, JsValue) - def deserializationError(msg: String, cause: Throwable = null) = throw new DeserializationException(msg, cause) + def deserializationError(msg: String, cause: Throwable = null, fieldNames: List[String] = Nil) = throw new DeserializationException(msg, cause, fieldNames) def serializationError(msg: String) = throw new SerializationException(msg) def jsonReader[T](implicit reader: JsonReader[T]) = reader @@ -32,7 +32,7 @@ package object json { package json { - class DeserializationException(msg: String, cause: Throwable = null) extends RuntimeException(msg, cause) + case class DeserializationException(msg: String, cause: Throwable = null, fieldNames: List[String] = Nil) extends RuntimeException(msg, cause) class SerializationException(msg: String) extends RuntimeException(msg) private[json] class PimpedAny[T](any: T) { @@ -44,4 +44,4 @@ package json { def asJson: JsValue = parseJson def parseJson: JsValue = JsonParser(string) } -}
\ No newline at end of file +} |