diff options
author | Mathias <mathias@decodified.com> | 2014-09-22 09:19:55 +0200 |
---|---|---|
committer | Mathias <mathias@decodified.com> | 2014-09-22 09:19:55 +0200 |
commit | dce0643476bd82a8a546900383a95fd72d1be243 (patch) | |
tree | 42b08c713fdf36238a3f2c7f791d2b26e475b1d7 /src/main | |
parent | a6aaf5164ae8b9dda62327c56349de9d97e7721c (diff) | |
parent | 12d83eb4b4b7c749cafe34f4a557c5ce153e4cdf (diff) | |
download | spray-json-dce0643476bd82a8a546900383a95fd72d1be243.tar.gz spray-json-dce0643476bd82a8a546900383a95fd72d1be243.tar.bz2 spray-json-dce0643476bd82a8a546900383a95fd72d1be243.zip |
Merge pull request #117 from chris-martin/jsonFormat0
Add jsonFormat0 for fieldless case classes
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/spray/json/ProductFormats.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/scala/spray/json/ProductFormats.scala b/src/main/scala/spray/json/ProductFormats.scala index 971c7a6..5f5a9f4 100644 --- a/src/main/scala/spray/json/ProductFormats.scala +++ b/src/main/scala/spray/json/ProductFormats.scala @@ -26,6 +26,15 @@ import scala.util.control.NonFatal trait ProductFormats extends ProductFormatsInstances { this: StandardFormats => + def jsonFormat0[T](construct: () => T): RootJsonFormat[T] = + new RootJsonFormat[T] { + def write(p: T) = JsObject() + def read(value: JsValue) = value match { + case JsObject(_) => construct() + case _ => throw new DeserializationException("Object expected") + } + } + // helpers protected def productElement2Field[T](fieldName: String, p: Product, ix: Int, rest: List[JsField] = Nil) |