Skip to content

Commit 42dfa08

Browse files
committed
Merge branch '2.12'
2 parents 4a0d61a + 914bdbb commit 42dfa08

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ JSON library.
2020
(contributed by Jendrik J)
2121
#619: Add `StreamReadCapability` for further format-based/format-agnostic
2222
handling improvements
23+
#627: Add `JsonParser.isExpectedNumberIntToken()` convenience method
2324
- Deprecate `JsonParser.getCurrentTokenId()` (use `#currentTokenId()` instead)
2425

2526
2.11.1 (25-Jun-2020)

src/main/java/com/fasterxml/jackson/core/JsonParser.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,22 @@ public Boolean nextBooleanValue() throws IOException {
632632
* start-array marker (such {@link JsonToken#START_ARRAY});
633633
* false if not.
634634
*/
635-
public boolean isExpectedStartArrayToken() { return currentToken() == JsonToken.START_ARRAY; }
635+
public abstract boolean isExpectedStartArrayToken();
636636

637637
/**
638638
* Similar to {@link #isExpectedStartArrayToken()}, but checks whether stream
639639
* currently points to {@link JsonToken#START_OBJECT}.
640640
*/
641-
public boolean isExpectedStartObjectToken() { return currentToken() == JsonToken.START_OBJECT; }
641+
public abstract boolean isExpectedStartObjectToken();
642+
643+
/**
644+
* Similar to {@link #isExpectedStartArrayToken()}, but checks whether stream
645+
* currently points to {@link JsonToken#VALUE_NUMBER_INT}.
646+
*<p>
647+
* The initial use case is for XML backend to efficiently (attempt to) coerce
648+
* textual content into numbers.
649+
*/
650+
public abstract boolean isExpectedNumberIntToken();
642651

643652
/**
644653
* Access for checking whether current token is a numeric value token, but
@@ -648,9 +657,7 @@ public Boolean nextBooleanValue() throws IOException {
648657
* NOTE: roughly equivalent to calling <code>!Double.isFinite()</code>
649658
* on value you would get from calling {@link #getDoubleValue()}.
650659
*/
651-
public boolean isNaN() throws IOException {
652-
return false;
653-
}
660+
public abstract boolean isNaN() throws IOException;
654661

655662
/*
656663
/**********************************************************************

src/main/java/com/fasterxml/jackson/core/StreamReadCapability.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @since 2.12
1414
*/
1515
public enum StreamReadCapability
16-
implements JacksonFeature // since 2.12
16+
implements JacksonFeature
1717
{
1818
/**
1919
* Capability that indicates that data format can expose multiple properties

src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public ObjectReadContext getObjectReadContext() {
295295

296296
@Override public boolean isExpectedStartArrayToken() { return _currToken == JsonToken.START_ARRAY; }
297297
@Override public boolean isExpectedStartObjectToken() { return _currToken == JsonToken.START_OBJECT; }
298+
@Override public boolean isExpectedNumberIntToken() { return _currToken == JsonToken.VALUE_NUMBER_INT; }
298299

299300
@Override
300301
public JsonToken nextValue() throws IOException {

src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public JsonParser disable(StreamReadFeature f) {
109109
@Override public TokenStreamContext getParsingContext() { return delegate.getParsingContext(); }
110110
@Override public boolean isExpectedStartArrayToken() { return delegate.isExpectedStartArrayToken(); }
111111
@Override public boolean isExpectedStartObjectToken() { return delegate.isExpectedStartObjectToken(); }
112+
@Override public boolean isExpectedNumberIntToken() { return delegate.isExpectedNumberIntToken(); }
113+
112114
@Override public boolean isNaN() throws IOException { return delegate.isNaN(); }
113115

114116
/*

src/test/java/com/fasterxml/jackson/core/read/NumberParsingTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private void _testSimpleInt(int EXP_I, int mode) throws Exception
7070
assertToken(JsonToken.START_ARRAY, p.nextToken());
7171
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
7272
assertEquals(JsonParser.NumberType.INT, p.getNumberType());
73+
assertTrue(p.isExpectedNumberIntToken());
7374
assertEquals(""+EXP_I, p.getText());
7475

7576
if (((short) EXP_I) == EXP_I) {
@@ -109,6 +110,7 @@ private void _testSimpleInt(int EXP_I, int mode) throws Exception
109110
DOC = String.valueOf(EXP_I);
110111
p = createParser(mode, DOC + " "); // DataInput requires separator
111112
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
113+
assertTrue(p.isExpectedNumberIntToken());
112114
assertEquals(DOC, p.getText());
113115

114116
int i = p.getIntValue();
@@ -123,6 +125,7 @@ private void _testSimpleInt(int EXP_I, int mode) throws Exception
123125
DOC = String.valueOf(EXP_I)+".0";
124126
p = createParser(mode, DOC + " ");
125127
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
128+
assertFalse(p.isExpectedNumberIntToken());
126129
assertEquals(EXP_I, p.getValueAsInt());
127130
p.close();
128131

src/test/java/com/fasterxml/jackson/core/util/TestDelegates.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public void testParserDelegate() throws IOException
148148
assertFalse(del.hasTokenId(JsonTokenId.ID_START_OBJECT));
149149
assertTrue(del.isExpectedStartArrayToken());
150150
assertFalse(del.isExpectedStartObjectToken());
151+
assertFalse(del.isExpectedNumberIntToken());
151152
assertEquals("[", del.getText());
152153
assertNotNull(del.getParsingContext());
153154
assertSame(parser.getParsingContext(), del.getParsingContext());
@@ -168,6 +169,7 @@ public void testParserDelegate() throws IOException
168169
assertEquals((short)1, del.getShortValue());
169170
assertEquals(1f, del.getFloatValue());
170171
assertFalse(del.isNaN());
172+
assertTrue(del.isExpectedNumberIntToken());
171173
assertEquals(NumberType.INT, del.getNumberType());
172174
assertEquals(Integer.valueOf(1), del.getNumberValue());
173175
assertNull(del.getEmbeddedObject());

0 commit comments

Comments
 (0)