Skip to content

Commit

Permalink
Merge branch '2.11' into 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 28, 2020
2 parents 264f51c + b5e5543 commit eeb266d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ James Agnew (jamesagnew@github)
* Contributed implementation of #611: Optionally allow leading decimal in float tokens
(2.11.0)

Pavel Krutikhin (pakru@github)
* Contributed fix for #647: Fix NPE in `writeNumber(String)` method of `UTF8JsonGenerator`,
`WriterBasedJsonGenerator`
(2.11.4)

Pavan Kalyan (pavan-kalyan@github)
* Contributed #500: Allow "optional-padding" for `Base64Variant`
(2.12.0)
Expand Down
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ JSON library.
#640: Add `JacksonException` as parent class of `JsonProcessingException`
- Deprecate `JsonParser.getCurrentTokenId()` (use `#currentTokenId()` instead)

2.11.4 (not yet released)

#647: Fix NPE in `writeNumber(String)` method of `UTF8JsonGenerator`,
`WriterBasedJsonGenerator`
(contributed by Pavel K)

2.11.3 (02-Oct-2020)
2.11.2 (02-Aug-2020)
2.11.1 (25-Jun-2020)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,9 @@ public void writeNumber(BigDecimal value) throws IOException
public void writeNumber(String encodedValue) throws IOException
{
_verifyValueWrite(WRITE_NUMBER);
if (_cfgNumbersAsStrings) {
if (encodedValue == null) {
_writeNull();
} else if (_cfgNumbersAsStrings) {
_writeQuotedRaw(encodedValue);
} else {
writeRaw(encodedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ public void writeNumber(BigDecimal value) throws IOException
public void writeNumber(String encodedValue) throws IOException
{
_verifyValueWrite(WRITE_NUMBER);
if (_cfgNumbersAsStrings) {
if (encodedValue == null) {
_writeNull();
} else if (_cfgNumbersAsStrings) {
_writeQuotedRaw(encodedValue);
} else {
writeRaw(encodedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ public void testNumbersAsJSONStrings() throws IOException
{
JsonFactory f = new JsonFactory();
// by default should output numbers as-is:
assertEquals("[1,2,3,1.25,2.25,3001,0.5,-1,12.3]", _writeNumbers(f, false));
assertEquals("[1,2,3,1.25,2.25,3001,0.5,-1,12.3]", _writeNumbers(f, true));
assertEquals("[1,2,3,1.25,2.25,3001,0.5,-1,12.3,null,null,null]", _writeNumbers(f, false));
assertEquals("[1,2,3,1.25,2.25,3001,0.5,-1,12.3,null,null,null]", _writeNumbers(f, true));

// but if overridden, quotes as Strings
f = JsonFactory.builder()
.enable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS)
.build();
assertEquals("[\"1\",\"2\",\"3\",\"1.25\",\"2.25\",\"3001\",\"0.5\",\"-1\",\"12.3\"]",
assertEquals("[\"1\",\"2\",\"3\",\"1.25\",\"2.25\",\"3001\",\"0.5\",\"-1\",\"12.3\",null,null,null]",
_writeNumbers(f, false));
assertEquals("[\"1\",\"2\",\"3\",\"1.25\",\"2.25\",\"3001\",\"0.5\",\"-1\",\"12.3\"]",
assertEquals("[\"1\",\"2\",\"3\",\"1.25\",\"2.25\",\"3001\",\"0.5\",\"-1\",\"12.3\",null,null,null]",
_writeNumbers(f, true));


Expand Down Expand Up @@ -228,6 +228,9 @@ private String _writeNumbers(JsonFactory f, boolean useBytes) throws IOException
g.writeNumber(BigDecimal.valueOf(0.5));
g.writeNumber("-1");
g.writeNumber(new char[]{'1', '2', '.', '3', '-'}, 0, 4);
g.writeNumber((String) null);
g.writeNumber((BigDecimal) null);
g.writeNumber((BigInteger) null);
g.writeEndArray();
g.close();

Expand Down

0 comments on commit eeb266d

Please sign in to comment.