Repository: incubator-groovy Updated Branches: refs/heads/master e6185f9e3 -> 84467fddc
GROOVY-7665 - JsonSlurperCharSource decimal parsing producing unexpected results (closes #183) Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/84467fdd Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/84467fdd Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/84467fdd Branch: refs/heads/master Commit: 84467fddc64744cc05d2b91b8704c753a9fb3d04 Parents: e6185f9 Author: John Wagenleitner <john.wagenleit...@gmail.com> Authored: Mon Nov 9 13:13:20 2015 -0800 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Mon Nov 9 23:17:22 2015 +0100 ---------------------------------------------------------------------- .../src/main/java/groovy/json/internal/CharScanner.java | 2 +- .../test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/84467fdd/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java index 156bd06..f140cf6 100644 --- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java +++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java @@ -684,7 +684,7 @@ public class CharScanner { } public static BigDecimal parseBigDecimal(char[] buffer, int from, int to) { - return new BigDecimal(parseDouble(buffer, from, to)); + return new BigDecimal(buffer, from, to); } public static float parseFloat(char[] buffer, int from, int to) { http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/84467fdd/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy index 9bf1265..19bff4b 100644 --- a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy +++ b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperCharSourceTest.groovy @@ -26,4 +26,10 @@ class JsonSlurperCharSourceTest extends JsonSlurperTest { void setUp() { parser = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE) } + + void testParsingDecimalValue() { + def num = parser.parseText('{"num": 123.40}').num + assert num instanceof BigDecimal + assert 123.40G == num + } }