diff options
author | Mathias <mathias@decodified.com> | 2015-05-06 09:36:14 +0200 |
---|---|---|
committer | Mathias <mathias@decodified.com> | 2015-05-06 09:36:14 +0200 |
commit | 9eb12c5f0df9331239f05956ab3cd6905e5e6cd5 (patch) | |
tree | 6021ddd921cf051dbfca8f4d0a4cd31e82ab952b /src/main/scala/spray | |
parent | 8467f8698a3abef894b0bb85dcfe54c2bab7a47c (diff) | |
parent | df74b880deef967465d981a1f688dc8936cf0a84 (diff) | |
download | spray-json-9eb12c5f0df9331239f05956ab3cd6905e5e6cd5.tar.gz spray-json-9eb12c5f0df9331239f05956ab3cd6905e5e6cd5.tar.bz2 spray-json-9eb12c5f0df9331239f05956ab3cd6905e5e6cd5.zip |
Merge pull request #152 from fommil/patch-1
standard optionFormat type close #151
Diffstat (limited to 'src/main/scala/spray')
-rw-r--r-- | src/main/scala/spray/json/StandardFormats.scala | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/main/scala/spray/json/StandardFormats.scala b/src/main/scala/spray/json/StandardFormats.scala index 154077a..e59de64 100644 --- a/src/main/scala/spray/json/StandardFormats.scala +++ b/src/main/scala/spray/json/StandardFormats.scala @@ -27,7 +27,7 @@ trait StandardFormats { private[json] type JF[T] = JsonFormat[T] // simple alias for reduced verbosity - implicit def optionFormat[T :JF] = new OptionFormat[T] + implicit def optionFormat[T :JF]: JF[Option[T]] = new OptionFormat[T] class OptionFormat[T :JF] extends JF[Option[T]] { def write(option: Option[T]) = option match { @@ -38,6 +38,8 @@ trait StandardFormats { case JsNull => None case x => Some(x.convertTo[T]) } + // allows reading the JSON as a Some (useful in container formats) + def readSome(value: JsValue) = Some(value.convertTo[T]) } implicit def eitherFormat[A :JF, B :JF] = new JF[Either[A, B]] { |