diff --git a/json-org/src/test/java/com/fasterxml/jackson/datatype/jsonorg/SimpleReadTest.java b/json-org/src/test/java/com/fasterxml/jackson/datatype/jsonorg/SimpleReadTest.java index c74d634..c1aae01 100644 --- a/json-org/src/test/java/com/fasterxml/jackson/datatype/jsonorg/SimpleReadTest.java +++ b/json-org/src/test/java/com/fasterxml/jackson/datatype/jsonorg/SimpleReadTest.java @@ -8,12 +8,11 @@ public class SimpleReadTest extends ModuleTestBase { + private final ObjectMapper MAPPER = newMapper(); + public void testReadObject() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JsonOrgModule()); - - JSONObject ob = mapper.readValue("{\"a\":{\"b\":3}, \"c\":[9, -4], \"d\":null, \"e\":true}", + JSONObject ob = MAPPER.readValue("{\"a\":{\"b\":3}, \"c\":[9, -4], \"d\":null, \"e\":true}", JSONObject.class); assertEquals(4, ob.length()); JSONObject ob2 = ob.getJSONObject("a"); @@ -29,10 +28,7 @@ public void testReadObject() throws Exception public void testReadArray() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JsonOrgModule()); - - JSONArray array = mapper.readValue("[null, 13, false, 1.25, \"abc\", {\"a\":13}, [ ] ]", + JSONArray array = MAPPER.readValue("[null, 13, false, 1.25, \"abc\", {\"a\":13}, [ ] ]", JSONArray.class); assertEquals(7, array.length()); assertTrue(array.isNull(0)); @@ -49,20 +45,20 @@ public void testReadArray() throws Exception public void testBigInteger() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JsonOrgModule()); - - JSONObject val = mapper.readValue("{\"val\":2e308}", JSONObject.class); + JSONObject val = MAPPER.readValue("{\"val\":2e308}", JSONObject.class); assertEquals(new BigDecimal("2e308").toBigInteger(), val.getBigInteger("val")); } public void testBigIntegerArray() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JsonOrgModule()); - - JSONArray array = mapper.readValue("[2e308]", JSONArray.class); + JSONArray array = MAPPER.readValue("[2e308]", JSONArray.class); assertEquals(1, array.length()); assertEquals(new BigDecimal("2e308").toBigInteger(), array.getBigInteger(0)); } + + public void testDouble() throws Exception + { + JSONObject val = MAPPER.readValue("{\"val\": 0.5}", JSONObject.class); + assertEquals(0.5d, val.getDouble("val")); + } } diff --git a/jsr-353/src/test/java/com/fasterxml/jackson/datatype/jsr353/JsonValueDeserializationTest.java b/jsr-353/src/test/java/com/fasterxml/jackson/datatype/jsr353/JsonValueDeserializationTest.java index a86ca04..db00856 100644 --- a/jsr-353/src/test/java/com/fasterxml/jackson/datatype/jsr353/JsonValueDeserializationTest.java +++ b/jsr-353/src/test/java/com/fasterxml/jackson/datatype/jsr353/JsonValueDeserializationTest.java @@ -155,4 +155,13 @@ public void testBigInteger() throws Exception // and round-tripping ought to be ok: assertEquals("[2E+308]", serializeAsString(v)); } + + public void testDouble() throws Exception + { + JsonValue val = MAPPER.readValue("{\"val\":0.5}", JsonValue.class); + JsonObject jsonObject = val.asJsonObject(); + JsonNumber jsonNumber = jsonObject.getJsonNumber("val"); + assertEquals(0.5d, jsonNumber.doubleValue()); + assertEquals(new BigDecimal(0.5d), jsonNumber.numberValue()); + } }