diff options
author | Konrad Malawski <konrad.malawski@project13.pl> | 2016-04-22 15:13:48 +0200 |
---|---|---|
committer | Konrad Malawski <konrad.malawski@project13.pl> | 2016-04-22 15:13:48 +0200 |
commit | aae2c6ef9e33e204aa4040689465804150ec226b (patch) | |
tree | 15eb41471d523aad67f6daf07827845214af866d /src | |
parent | 4fbde3a833cb122c71aaf85a1b3bbd31e130cb62 (diff) | |
download | spray-json-aae2c6ef9e33e204aa4040689465804150ec226b.tar.gz spray-json-aae2c6ef9e33e204aa4040689465804150ec226b.tar.bz2 spray-json-aae2c6ef9e33e204aa4040689465804150ec226b.zip |
+#182 allows BigInt/BigDecimal to be obtained from JsStrings
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/spray/json/BasicFormats.scala | 2 | ||||
-rw-r--r-- | src/test/scala/spray/json/BasicFormatsSpec.scala | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/main/scala/spray/json/BasicFormats.scala b/src/main/scala/spray/json/BasicFormats.scala index 96751f6..65b9ecb 100644 --- a/src/main/scala/spray/json/BasicFormats.scala +++ b/src/main/scala/spray/json/BasicFormats.scala @@ -79,6 +79,7 @@ trait BasicFormats { } def read(value: JsValue) = value match { case JsNumber(x) => x + case JsString(x) => BigDecimal(x) case x => deserializationError("Expected BigDecimal as JsNumber, but got " + x) } } @@ -90,6 +91,7 @@ trait BasicFormats { } def read(value: JsValue) = value match { case JsNumber(x) => x.toBigInt + case JsString(x) => BigInt(x) case x => deserializationError("Expected BigInt as JsNumber, but got " + x) } } diff --git a/src/test/scala/spray/json/BasicFormatsSpec.scala b/src/test/scala/spray/json/BasicFormatsSpec.scala index 629c223..00da813 100644 --- a/src/test/scala/spray/json/BasicFormatsSpec.scala +++ b/src/test/scala/spray/json/BasicFormatsSpec.scala @@ -105,6 +105,9 @@ class BasicFormatsSpec extends Specification with DefaultJsonProtocol { "convert a JsNumber to a BigDecimal" in { JsNumber(42).convertTo[BigDecimal] mustEqual BigDecimal(42) } + """convert a JsString to a BigDecimal (to allow the quoted-large-numbers pattern)""" in { + JsString("9223372036854775809").convertTo[BigDecimal] mustEqual BigDecimal("9223372036854775809") + } } "The BigIntJsonFormat" should { @@ -114,6 +117,9 @@ class BasicFormatsSpec extends Specification with DefaultJsonProtocol { "convert a JsNumber to a BigInt" in { JsNumber(42).convertTo[BigInt] mustEqual BigInt(42) } + """convert a JsString to a BigInt (to allow the quoted-large-numbers pattern)""" in { + JsString("9223372036854775809").convertTo[BigInt] mustEqual BigInt("9223372036854775809") + } } "The UnitJsonFormat" should { |