diff options
Diffstat (limited to 'src/main/scala')
-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 +} |