Skip to content

Commit

Permalink
Initial changes wrt #3651
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 6, 2022
1 parent d075058 commit 7f4a8a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class JsonNodeFactory
* Default singleton instance that construct "standard" node instances:
* given that this class is stateless, a globally shared singleton
* can be used.
*<p>
* Default for 3.x is to make no changes; no normalization by default.
*/
public final static JsonNodeFactory instance = decimalsNormalized;
public final static JsonNodeFactory instance = decimalsAsIs;

/**
* Main constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,17 @@ 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
// By default, 2.x WILL normalize but 3.x WON'T
JsonNode n1 = MAPPER.readTree(String.valueOf(NON_NORMALIZED));
assertEquals(NORMALIZED, n1.decimalValue());
assertEquals(NON_NORMALIZED, n1.decimalValue());

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

JsonNodeFactory nf = JsonNodeFactory.withExactBigDecimals(false);
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());
assertEquals(NORMALIZED, n3.decimalValue());
}
}

0 comments on commit 7f4a8a0

Please sign in to comment.