Skip to content

Commit

Permalink
Merge branch '2.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 6, 2022
2 parents 536065e + 9ced6e6 commit d075058
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ public ValueNode numberNode(BigDecimal v)
if (v == null) {
return nullNode();
}

/*
* If the user wants the exact representation of this big decimal,
* return the value directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

public class JsonNodeFactoryTest extends NodeTestBase
{
private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = JsonMapper.builder()
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.build();

static class SortingNodeFactory extends JsonNodeFactory {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -72,4 +74,27 @@ public void testSortingObjectNode() throws Exception
assertEquals(BIGGER_OUTPUT,
MAPPER.writeValueAsString(mapper.readTree(BIGGER_INPUT)));
}

// 06-Nov-2022, tatu: Wasn't being tests, oddly enough
public void testBigDecimalNormalization() throws Exception
{
final BigDecimal NON_NORMALIZED = new BigDecimal("12.5000");
final BigDecimal NORMALIZED = NON_NORMALIZED.stripTrailingZeros();

// By default, 2.x WILL normalize
JsonNode n1 = MAPPER.readTree(String.valueOf(NON_NORMALIZED));
assertEquals(NORMALIZED, n1.decimalValue());

// But can change
JsonNodeFactory nf = JsonNodeFactory.withExactBigDecimals(true);
JsonNode n2 = nf.numberNode(NON_NORMALIZED);
assertEquals(NON_NORMALIZED, n2.decimalValue());

ObjectMapper nonNormMapper = JsonMapper.builder()
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.nodeFactory(nf)
.build();
JsonNode n3 = nonNormMapper.readTree(String.valueOf(NON_NORMALIZED));
assertEquals(NON_NORMALIZED, n3.decimalValue());
}
}

0 comments on commit d075058

Please sign in to comment.