diff options
author | Johannes Rudolph <johannes.rudolph@gmail.com> | 2014-03-13 09:56:06 +0100 |
---|---|---|
committer | Johannes Rudolph <johannes.rudolph@gmail.com> | 2014-03-13 10:02:48 +0100 |
commit | 6fe0b1f5f9dba42c62508a1eba5c3565a8d6f765 (patch) | |
tree | 7f8ab907b20979cbeb14d5a7743b51225b095cd4 /src/main/scala/spray/json/BasicFormats.scala | |
parent | 63b95d7a2abfc964fc477dbf6024184cbba83224 (diff) | |
download | spray-json-6fe0b1f5f9dba42c62508a1eba5c3565a8d6f765.tar.gz spray-json-6fe0b1f5f9dba42c62508a1eba5c3565a8d6f765.tar.bz2 spray-json-6fe0b1f5f9dba42c62508a1eba5c3565a8d6f765.zip |
Make sure BasicFormats never pass `null` into JsValue constructors, fixes #70
Diffstat (limited to 'src/main/scala/spray/json/BasicFormats.scala')
-rw-r--r-- | src/main/scala/spray/json/BasicFormats.scala | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/scala/spray/json/BasicFormats.scala b/src/main/scala/spray/json/BasicFormats.scala index 55fe0bf..96751f6 100644 --- a/src/main/scala/spray/json/BasicFormats.scala +++ b/src/main/scala/spray/json/BasicFormats.scala @@ -73,7 +73,10 @@ trait BasicFormats { } implicit object BigDecimalJsonFormat extends JsonFormat[BigDecimal] { - def write(x: BigDecimal) = JsNumber(x) + def write(x: BigDecimal) = { + require(x ne null) + JsNumber(x) + } def read(value: JsValue) = value match { case JsNumber(x) => x case x => deserializationError("Expected BigDecimal as JsNumber, but got " + x) @@ -81,7 +84,10 @@ trait BasicFormats { } implicit object BigIntJsonFormat extends JsonFormat[BigInt] { - def write(x: BigInt) = JsNumber(x) + def write(x: BigInt) = { + require(x ne null) + JsNumber(x) + } def read(value: JsValue) = value match { case JsNumber(x) => x.toBigInt case x => deserializationError("Expected BigInt as JsNumber, but got " + x) @@ -111,7 +117,10 @@ trait BasicFormats { } implicit object StringJsonFormat extends JsonFormat[String] { - def write(x: String) = JsString(x) + def write(x: String) = { + require(x ne null) + JsString(x) + } def read(value: JsValue) = value match { case JsString(x) => x case x => deserializationError("Expected String as JsString, but got " + x) @@ -125,5 +134,4 @@ trait BasicFormats { case x => deserializationError("Expected Symbol as JsString, but got " + x) } } - } |