Skip to content

Commit

Permalink
Merge branch '2.14' into 2.15
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 26, 2023
2 parents 8608f13 + f7eeba6 commit 86f8207
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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));
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 86f8207

Please sign in to comment.