Skip to content

Commit dd6914d

Browse files
committed
More cleanup wrt now-deprecated JsonParser getter methods
1 parent 6b0125d commit dd6914d

12 files changed

+162
-80
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ public void copyCurrentEvent(JsonParser p) throws IOException
24782478
writeEndArray();
24792479
break;
24802480
case ID_FIELD_NAME:
2481-
writeFieldName(p.getCurrentName());
2481+
writeFieldName(p.currentName());
24822482
break;
24832483
case ID_STRING:
24842484
_copyCurrentStringValue(p);
@@ -2542,7 +2542,7 @@ public void copyCurrentEventExact(JsonParser p) throws IOException
25422542
writeEndArray();
25432543
break;
25442544
case ID_FIELD_NAME:
2545-
writeFieldName(p.getCurrentName());
2545+
writeFieldName(p.currentName());
25462546
break;
25472547
case ID_STRING:
25482548
_copyCurrentStringValue(p);
@@ -2617,7 +2617,7 @@ public void copyCurrentStructure(JsonParser p) throws IOException
26172617
// Let's handle field-name separately first
26182618
int id = (t == null) ? ID_NOT_AVAILABLE : t.id();
26192619
if (id == ID_FIELD_NAME) {
2620-
writeFieldName(p.getCurrentName());
2620+
writeFieldName(p.currentName());
26212621
t = p.nextToken();
26222622
id = (t == null) ? ID_NOT_AVAILABLE : t.id();
26232623
// fall-through to copy the associated value
@@ -2647,7 +2647,7 @@ protected void _copyCurrentContents(JsonParser p) throws IOException
26472647
while ((t = p.nextToken()) != null) {
26482648
switch (t.id()) {
26492649
case ID_FIELD_NAME:
2650-
writeFieldName(p.getCurrentName());
2650+
writeFieldName(p.currentName());
26512651
break;
26522652

26532653
case ID_START_ARRAY:

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
10461046
* time to get the value for the field.
10471047
* Method is most useful for iterating over value entries
10481048
* of JSON objects; field name will still be available
1049-
* by calling {@link #getCurrentName} when parser points to
1049+
* by calling {@link #currentName} when parser points to
10501050
* the value.
10511051
*
10521052
* @return Next non-field-name token from the stream, if any found,
@@ -1065,7 +1065,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
10651065
* and returns result of that comparison.
10661066
* It is functionally equivalent to:
10671067
*<pre>
1068-
* return (nextToken() == JsonToken.FIELD_NAME) &amp;&amp; str.getValue().equals(getCurrentName());
1068+
* return (nextToken() == JsonToken.FIELD_NAME) &amp;&amp; str.getValue().equals(currentName());
10691069
*</pre>
10701070
* but may be faster for parser to verify, and can therefore be used if caller
10711071
* expects to get such a property name from input next.
@@ -1080,13 +1080,13 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
10801080
* {@link JsonParseException} for decoding problems
10811081
*/
10821082
public boolean nextFieldName(SerializableString str) throws IOException {
1083-
return (nextToken() == JsonToken.FIELD_NAME) && str.getValue().equals(getCurrentName());
1083+
return (nextToken() == JsonToken.FIELD_NAME) && str.getValue().equals(currentName());
10841084
}
10851085

10861086
/**
10871087
* Method that fetches next token (as if calling {@link #nextToken}) and
10881088
* verifies whether it is {@link JsonToken#FIELD_NAME}; if it is,
1089-
* returns same as {@link #getCurrentName()}, otherwise null.
1089+
* returns same as {@link #currentName()}, otherwise null.
10901090
*
10911091
* @return Name of the the {@code JsonToken.FIELD_NAME} parser advanced to, if any;
10921092
* {@code null} if next token is of some other type
@@ -1097,7 +1097,7 @@ public boolean nextFieldName(SerializableString str) throws IOException {
10971097
* @since 2.5
10981098
*/
10991099
public String nextFieldName() throws IOException {
1100-
return (nextToken() == JsonToken.FIELD_NAME) ? getCurrentName() : null;
1100+
return (nextToken() == JsonToken.FIELD_NAME) ? currentName() : null;
11011101
}
11021102

11031103
/**
@@ -1262,6 +1262,7 @@ public void finishToken() throws IOException {
12621262
* @since 2.8
12631263
*/
12641264
public JsonToken currentToken() {
1265+
// !!! TODO: switch direction in 2.18 or later
12651266
return getCurrentToken();
12661267
}
12671268

@@ -1478,14 +1479,14 @@ public boolean isNaN() throws IOException {
14781479
*/
14791480

14801481
/**
1481-
* Alias of {@link #currentName()}.
1482+
* Deprecated lias of {@link #currentName()}.
14821483
*
14831484
* @return Name of the current field in the parsing context
14841485
*
14851486
* @throws IOException for low-level read issues, or
14861487
* {@link JsonParseException} for decoding problems
14871488
*
1488-
* @deprecated use {@link #currentName} instead.
1489+
* @deprecated Since 2.17 use {@link #currentName} instead.
14891490
*/
14901491
@Deprecated
14911492
public abstract String getCurrentName() throws IOException;
@@ -1505,6 +1506,7 @@ public boolean isNaN() throws IOException {
15051506
* @since 2.10
15061507
*/
15071508
public String currentName() throws IOException {
1509+
// !!! TODO: switch direction in 2.18 or later
15081510
return getCurrentName();
15091511
}
15101512

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,16 @@ protected ParserBase(IOContext ctxt, int features) {
278278
_parsingContext = JsonReadContext.createRootContext(dups);
279279
}
280280

281-
@Override public Version version() { return PackageVersion.VERSION; }
281+
@Override
282+
public Version version() { return PackageVersion.VERSION; }
282283

283284
@Override
284-
public Object getCurrentValue() {
285+
public Object currentValue() {
285286
return _parsingContext.getCurrentValue();
286287
}
287288

288289
@Override
289-
public void setCurrentValue(Object v) {
290+
public void assignCurrentValue(Object v) {
290291
_parsingContext.setCurrentValue(v);
291292
}
292293

@@ -373,7 +374,9 @@ protected void _checkStdFeatureChanges(int newFeatureFlags, int changedFeatures)
373374
* Method that can be called to get the name associated with
374375
* the current event.
375376
*/
376-
@Override public String getCurrentName() throws IOException {
377+
@Deprecated // since 2.17
378+
@Override
379+
public String getCurrentName() throws IOException {
377380
// [JACKSON-395]: start markers require information from parent
378381
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
379382
JsonReadContext parent = _parsingContext.getParent();
@@ -384,7 +387,8 @@ protected void _checkStdFeatureChanges(int newFeatureFlags, int changedFeatures)
384387
return _parsingContext.getCurrentName();
385388
}
386389

387-
@Override public void overrideCurrentName(String name) {
390+
@Override
391+
public void overrideCurrentName(String name) {
388392
// Simple, but need to look for START_OBJECT/ARRAY's "off-by-one" thing:
389393
JsonReadContext ctxt = _parsingContext;
390394
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
@@ -424,6 +428,7 @@ protected void _checkStdFeatureChanges(int newFeatureFlags, int changedFeatures)
424428
* that starts the current token.
425429
*/
426430
@Override
431+
@Deprecated // since 2.17
427432
public JsonLocation getTokenLocation() {
428433
return new JsonLocation(_contentReference(),
429434
-1L, getTokenCharacterOffset(), // bytes, chars
@@ -436,6 +441,7 @@ public JsonLocation getTokenLocation() {
436441
* usually for error reporting purposes
437442
*/
438443
@Override
444+
@Deprecated // since 2.17
439445
public JsonLocation getCurrentLocation() {
440446
int col = _inputPtr - _currInputRowStart + 1; // 1-based
441447
return new JsonLocation(_contentReference(),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ public JsonParser skipChildren() throws IOException
276276
//public JsonToken getCurrentToken()
277277
//public boolean hasCurrentToken()
278278

279-
@Override public abstract String getCurrentName() throws IOException;
279+
@Deprecated // since 2.17 -- still need to implement
280+
@Override
281+
public abstract String getCurrentName() throws IOException;
282+
280283
@Override public abstract void close() throws IOException;
281284
@Override public abstract boolean isClosed();
282285

@@ -490,7 +493,7 @@ public String getValueAsString(String defaultValue) throws IOException {
490493
return getText();
491494
}
492495
if (_currToken == JsonToken.FIELD_NAME) {
493-
return getCurrentName();
496+
return currentName();
494497
}
495498
if (_currToken == null || _currToken == JsonToken.VALUE_NULL || !_currToken.isScalarValue()) {
496499
return defaultValue;

src/main/java/com/fasterxml/jackson/core/exc/StreamReadException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public abstract class StreamReadException
2727
protected RequestPayload _requestPayload;
2828

2929
protected StreamReadException(JsonParser p, String msg) {
30-
super(msg, (p == null) ? null : p.getCurrentLocation());
30+
super(msg, (p == null) ? null : p.currentLocation());
3131
_processor = p;
3232
}
3333

3434
protected StreamReadException(JsonParser p, String msg, Throwable root) {
35-
super(msg, (p == null) ? null : p.getCurrentLocation(), root);
35+
super(msg, (p == null) ? null : p.currentLocation(), root);
3636
_processor = p;
3737
}
3838

src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,20 @@ public int getMatchCount() {
150150
/**********************************************************
151151
*/
152152

153-
@Override public JsonToken getCurrentToken() { return _currToken; }
154153
@Override public JsonToken currentToken() { return _currToken; }
155154

156-
@Deprecated // since 2.12
157-
@Override public final int getCurrentTokenId() {
158-
return currentTokenId();
159-
}
155+
@Override
156+
@Deprecated // since 2.17
157+
public JsonToken getCurrentToken() { return _currToken; }
158+
160159
@Override public final int currentTokenId() {
161160
final JsonToken t = _currToken;
162161
return (t == null) ? JsonTokenId.ID_NO_TOKEN : t.id();
163162
}
163+
@Deprecated // since 2.12
164+
@Override public final int getCurrentTokenId() {
165+
return currentTokenId();
166+
}
164167

165168
@Override public boolean hasCurrentToken() { return _currToken != null; }
166169
@Override public boolean hasTokenId(int id) {
@@ -178,15 +181,31 @@ public int getMatchCount() {
178181
@Override public boolean isExpectedStartArrayToken() { return _currToken == JsonToken.START_ARRAY; }
179182
@Override public boolean isExpectedStartObjectToken() { return _currToken == JsonToken.START_OBJECT; }
180183

181-
@Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); }
184+
@Override
185+
public JsonLocation currentLocation() {
186+
return delegate.currentLocation();
187+
}
182188

189+
@Override
190+
@Deprecated // since 2.17
191+
public JsonLocation getCurrentLocation() {
192+
return delegate.getCurrentLocation();
193+
}
194+
195+
@Override
196+
public JsonLocation currentTokenLocation() { return delegate.currentTokenLocation(); }
197+
198+
@Override
199+
@Deprecated // since 2.17
200+
public JsonLocation getTokenLocation() { return delegate.getTokenLocation(); }
201+
183202
@Override
184203
public JsonStreamContext getParsingContext() {
185204
return _filterContext();
186205
}
187206

188-
// !!! TODO: Verify it works as expected: copied from standard JSON parser impl
189207
@Override
208+
@Deprecated // since 2.17
190209
public String getCurrentName() throws IOException {
191210
JsonStreamContext ctxt = _filterContext();
192211
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
@@ -419,7 +438,7 @@ public JsonToken nextToken() throws IOException
419438

420439
case ID_FIELD_NAME:
421440
{
422-
final String name = delegate.getCurrentName();
441+
final String name = delegate.currentName();
423442
// note: this will also set 'needToHandleName'
424443
f = _headContext.setFieldName(name);
425444
if (f == TokenFilter.INCLUDE_ALL) {
@@ -609,7 +628,7 @@ protected final JsonToken _nextToken2() throws IOException
609628

610629
case ID_FIELD_NAME:
611630
{
612-
final String name = delegate.getCurrentName();
631+
final String name = delegate.currentName();
613632
f = _headContext.setFieldName(name);
614633
if (f == TokenFilter.INCLUDE_ALL) {
615634
_itemFilter = f;
@@ -796,7 +815,7 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
796815

797816
case ID_FIELD_NAME:
798817
{
799-
final String name = delegate.getCurrentName();
818+
final String name = delegate.currentName();
800819
f = _headContext.setFieldName(name);
801820
if (f == TokenFilter.INCLUDE_ALL) {
802821
_itemFilter = f;
@@ -1046,7 +1065,6 @@ public JsonParser skipChildren() throws IOException
10461065
@Override public Object getEmbeddedObject() throws IOException { return delegate.getEmbeddedObject(); }
10471066
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException { return delegate.getBinaryValue(b64variant); }
10481067
@Override public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException { return delegate.readBinaryValue(b64variant, out); }
1049-
@Override public JsonLocation getTokenLocation() { return delegate.getTokenLocation(); }
10501068

10511069
/*
10521070
/**********************************************************

src/main/java/com/fasterxml/jackson/core/json/DupDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void reset() {
5858
public JsonLocation findLocation() {
5959
// ugly but:
6060
if (_source instanceof JsonParser) {
61-
return ((JsonParser)_source).getCurrentLocation();
61+
return ((JsonParser)_source).currentLocation();
6262
}
6363
// do generators have a way to provide Location? Apparently not...
6464
return null;

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public final String getValueAsString() throws IOException
372372
return _textBuffer.contentsAsString();
373373
}
374374
if (_currToken == JsonToken.FIELD_NAME) {
375-
return getCurrentName();
375+
return currentName();
376376
}
377377
return super.getValueAsString(null);
378378
}
@@ -388,7 +388,7 @@ public final String getValueAsString(String defValue) throws IOException {
388388
return _textBuffer.contentsAsString();
389389
}
390390
if (_currToken == JsonToken.FIELD_NAME) {
391-
return getCurrentName();
391+
return currentName();
392392
}
393393
return super.getValueAsString(defValue);
394394
}
@@ -2973,7 +2973,15 @@ protected byte[] _decodeBase64(Base64Variant b64variant) throws IOException
29732973
*/
29742974

29752975
@Override
2976-
public JsonLocation getTokenLocation()
2976+
public JsonLocation currentLocation() {
2977+
final int col = _inputPtr - _currInputRowStart + 1; // 1-based
2978+
return new JsonLocation(_contentReference(),
2979+
-1L, _currInputProcessed + _inputPtr,
2980+
_currInputRow, col);
2981+
}
2982+
2983+
@Override
2984+
public JsonLocation currentTokenLocation()
29772985
{
29782986
if (_currToken == JsonToken.FIELD_NAME) {
29792987
long total = _currInputProcessed + (_nameStartOffset-1);
@@ -2984,12 +2992,16 @@ public JsonLocation getTokenLocation()
29842992
-1L, _tokenInputTotal-1, _tokenInputRow, _tokenInputCol);
29852993
}
29862994

2995+
@Deprecated // since 2.17
29872996
@Override
29882997
public JsonLocation getCurrentLocation() {
2989-
final int col = _inputPtr - _currInputRowStart + 1; // 1-based
2990-
return new JsonLocation(_contentReference(),
2991-
-1L, _currInputProcessed + _inputPtr,
2992-
_currInputRow, col);
2998+
return currentLocation();
2999+
}
3000+
3001+
@Deprecated // since 2.17
3002+
@Override
3003+
public JsonLocation getTokenLocation() {
3004+
return currentTokenLocation();
29933005
}
29943006

29953007
// @since 2.7

0 commit comments

Comments
 (0)