diff options
author | Sam Halliday <sam.halliday@Gmail.com> | 2015-04-25 12:56:53 +0100 |
---|---|---|
committer | Sam Halliday <sam.halliday@gmail.com> | 2015-04-25 18:43:00 +0100 |
commit | df74b880deef967465d981a1f688dc8936cf0a84 (patch) | |
tree | 31b4e261eea2562f3bac4291e47a3108d1b6558a /src/main | |
parent | f56576932f98227ef1bd37981a46562d053f8409 (diff) | |
download | spray-json-df74b880deef967465d981a1f688dc8936cf0a84.tar.gz spray-json-df74b880deef967465d981a1f688dc8936cf0a84.tar.bz2 spray-json-df74b880deef967465d981a1f688dc8936cf0a84.zip |
standard optionFormat type close #151
Diffstat (limited to 'src/main')
-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]] { |