Skip to content

Commit dfa3b11

Browse files
committed
Backport #671
1 parent 99bf0cf commit dfa3b11

File tree

4 files changed

+95
-50
lines changed

4 files changed

+95
-50
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ JSON library.
1717
2.13.0 (not yet released)
1818

1919
#664: Add `StreamWriteException` type to eventually replace `JsonGenerationException`
20+
#671: Add `getCurrentLocation()`/`getTokenLocation()` to replace
21+
`currentLocation()`/`currentTokenLocation()`
2022

2123
2.12.1 (08-Jan-2021)
2224

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,35 +682,63 @@ public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() {
682682
public abstract JsonStreamContext getParsingContext();
683683

684684
/**
685-
* Method that return the <b>starting</b> location of the current
686-
* token; that is, position of the first character from input
687-
* that starts the current token.
685+
* Method that returns location of the last processed input unit (character
686+
* or byte) from the input;
687+
* usually for error reporting purposes.
688688
*<p>
689689
* Note that the location is not guaranteed to be accurate (although most
690690
* implementation will try their best): some implementations may only
691-
* return {@link JsonLocation#NA} due to not having access
691+
* report specific boundary locations (start or end locations of tokens)
692+
* and others only return {@link JsonLocation#NA} due to not having access
692693
* to input location information (when delegating actual decoding work
693694
* to other library)
694695
*
695-
* @return Starting location of the token parser currently points to
696+
* @return Location of the last processed input unit (byte or character)
697+
*
698+
* @since 2.13
696699
*/
697-
public abstract JsonLocation getTokenLocation();
700+
public JsonLocation currentLocation() {
701+
return getCurrentLocation();
702+
}
698703

699704
/**
700-
* Method that returns location of the last processed character;
701-
* usually for error reporting purposes.
705+
* Method that return the <b>starting</b> location of the current
706+
* (most recently returned)
707+
* token; that is, the position of the first input unit (character or byte) from input
708+
* that starts the current token.
702709
*<p>
703710
* Note that the location is not guaranteed to be accurate (although most
704711
* implementation will try their best): some implementations may only
705-
* report specific boundary locations (start or end locations of tokens)
706-
* and others only return {@link JsonLocation#NA} due to not having access
712+
* return {@link JsonLocation#NA} due to not having access
707713
* to input location information (when delegating actual decoding work
708714
* to other library)
709715
*
716+
* @return Starting location of the token parser currently points to
717+
*
718+
* @since 2.13 (will eventually replace {@link #getTokenLocation})
719+
*/
720+
public JsonLocation currentTokenLocation() {
721+
return getTokenLocation();
722+
}
723+
724+
// TODO: deprecate in 2.14 or later
725+
/**
726+
* Alias for {@link #currentLocation()}, to be deprecated in later
727+
* Jackson 2.x versions (and removed from Jackson 3.0).
728+
*
710729
* @return Location of the last processed input unit (byte or character)
711730
*/
712731
public abstract JsonLocation getCurrentLocation();
713732

733+
// TODO: deprecate in 2.14 or later
734+
/**
735+
* Alias for {@link #currentTokenLocation()}, to be deprecated in later
736+
* Jackson 2.x versions (and removed from Jackson 3.0).
737+
*
738+
* @return Starting location of the token parser currently points to
739+
*/
740+
public abstract JsonLocation getTokenLocation();
741+
714742
/*
715743
/**********************************************************
716744
/* Buffer handling

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

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public void setCurrentValue(Object v) {
3737
}
3838

3939
/*
40-
/**********************************************************
40+
/**********************************************************************
4141
/* Public API, configuration
42-
/**********************************************************
42+
/**********************************************************************
4343
*/
4444

4545
@Override public void setCodec(ObjectCodec c) { delegate.setCodec(c); }
@@ -86,65 +86,81 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
8686
@Override public Object getInputSource() { return delegate.getInputSource(); }
8787

8888
/*
89-
/**********************************************************
89+
/**********************************************************************
9090
/* Capability introspection
91-
/**********************************************************
91+
/**********************************************************************
9292
*/
9393

9494
@Override public boolean requiresCustomCodec() { return delegate.requiresCustomCodec(); }
9595

9696
@Override public JacksonFeatureSet<StreamReadCapability> getReadCapabilities() { return delegate.getReadCapabilities(); }
9797

9898
/*
99-
/**********************************************************
99+
/**********************************************************************
100100
/* Closeable impl
101-
/**********************************************************
101+
/**********************************************************************
102102
*/
103103

104104
@Override public void close() throws IOException { delegate.close(); }
105105
@Override public boolean isClosed() { return delegate.isClosed(); }
106106

107107
/*
108-
/**********************************************************
109-
/* Public API, token accessors
110-
/**********************************************************
108+
/**********************************************************************
109+
/* Public API, state override methods
110+
/**********************************************************************
111111
*/
112+
113+
@Override public void clearCurrentToken() { delegate.clearCurrentToken(); }
114+
@Override public JsonToken getLastClearedToken() { return delegate.getLastClearedToken(); }
115+
@Override public void overrideCurrentName(String name) { delegate.overrideCurrentName(name); }
112116

117+
/*
118+
/**********************************************************************
119+
/* Public API, state/location accessors
120+
/**********************************************************************
121+
*/
122+
123+
@Override public JsonStreamContext getParsingContext() { return delegate.getParsingContext(); }
124+
113125
@Override public JsonToken currentToken() { return delegate.currentToken(); }
114126
@Override public int currentTokenId() { return delegate.currentTokenId(); }
115-
116-
@Override public JsonToken getCurrentToken() { return delegate.getCurrentToken(); }
127+
@Override public String currentName() throws IOException { return delegate.currentName(); }
128+
129+
@Override public JsonLocation currentLocation() { return delegate.getCurrentLocation(); }
130+
@Override public JsonLocation currentTokenLocation() { return delegate.getTokenLocation(); }
117131

132+
// TODO: deprecate in 2.14 or later
133+
@Override public JsonToken getCurrentToken() { return delegate.getCurrentToken(); }
118134
@Deprecated // since 2.12
119135
@Override public int getCurrentTokenId() { return delegate.getCurrentTokenId(); }
136+
// TODO: deprecate in 2.14 or later
137+
@Override public String getCurrentName() throws IOException { return delegate.getCurrentName(); }
138+
139+
// TODO: deprecate in 2.14 or later
140+
@Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); }
141+
// TODO: deprecate in 2.14 or later
142+
@Override public JsonLocation getTokenLocation() { return delegate.getTokenLocation(); }
143+
144+
/*
145+
/**********************************************************************
146+
/* Public API, token accessors
147+
/**********************************************************************
148+
*/
120149

121150
@Override public boolean hasCurrentToken() { return delegate.hasCurrentToken(); }
122151
@Override public boolean hasTokenId(int id) { return delegate.hasTokenId(id); }
123152
@Override public boolean hasToken(JsonToken t) { return delegate.hasToken(t); }
124153

125-
@Override public String getCurrentName() throws IOException { return delegate.getCurrentName(); }
126-
@Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); }
127-
@Override public JsonStreamContext getParsingContext() { return delegate.getParsingContext(); }
128154
@Override public boolean isExpectedStartArrayToken() { return delegate.isExpectedStartArrayToken(); }
129155
@Override public boolean isExpectedStartObjectToken() { return delegate.isExpectedStartObjectToken(); }
130156
@Override public boolean isExpectedNumberIntToken() { return delegate.isExpectedNumberIntToken(); }
131157

132158
@Override public boolean isNaN() throws IOException { return delegate.isNaN(); }
133159

134160
/*
135-
/**********************************************************
136-
/* Public API, token state overrides
137-
/**********************************************************
138-
*/
139-
140-
@Override public void clearCurrentToken() { delegate.clearCurrentToken(); }
141-
@Override public JsonToken getLastClearedToken() { return delegate.getLastClearedToken(); }
142-
@Override public void overrideCurrentName(String name) { delegate.overrideCurrentName(name); }
143-
144-
/*
145-
/**********************************************************
146-
/* Public API, access to token information, text
147-
/**********************************************************
161+
/**********************************************************************
162+
/* Public API, access to token textual content
163+
/**********************************************************************
148164
*/
149165

150166
@Override public String getText() throws IOException { return delegate.getText(); }
@@ -155,9 +171,9 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
155171
@Override public int getText(Writer writer) throws IOException, UnsupportedOperationException { return delegate.getText(writer); }
156172

157173
/*
158-
/**********************************************************
159-
/* Public API, access to token information, numeric
160-
/**********************************************************
174+
/**********************************************************************
175+
/* Public API, access to token numeric values
176+
/**********************************************************************
161177
*/
162178

163179
@Override
@@ -197,9 +213,9 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
197213
public Number getNumberValueExact() throws IOException { return delegate.getNumberValueExact(); }
198214

199215
/*
200-
/**********************************************************
216+
/**********************************************************************
201217
/* Public API, access to token information, coercion/conversion
202-
/**********************************************************
218+
/**********************************************************************
203219
*/
204220

205221
@Override public int getValueAsInt() throws IOException { return delegate.getValueAsInt(); }
@@ -214,15 +230,14 @@ public JsonParser overrideFormatFeatures(int values, int mask) {
214230
@Override public String getValueAsString(String defaultValue) throws IOException { return delegate.getValueAsString(defaultValue); }
215231

216232
/*
217-
/**********************************************************
233+
/**********************************************************************
218234
/* Public API, access to token values, other
219-
/**********************************************************
235+
/**********************************************************************
220236
*/
221237

222238
@Override public Object getEmbeddedObject() throws IOException { return delegate.getEmbeddedObject(); }
223239
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException { return delegate.getBinaryValue(b64variant); }
224240
@Override public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException { return delegate.readBinaryValue(b64variant, out); }
225-
@Override public JsonLocation getTokenLocation() { return delegate.getTokenLocation(); }
226241

227242
@Override public JsonToken nextToken() throws IOException { return delegate.nextToken(); }
228243

@@ -238,9 +253,9 @@ public JsonParser skipChildren() throws IOException {
238253
}
239254

240255
/*
241-
/**********************************************************
256+
/**********************************************************************
242257
/* Public API, Native Ids (type, object)
243-
/**********************************************************
258+
/**********************************************************************
244259
*/
245260

246261
@Override public boolean canReadObjectId() { return delegate.canReadObjectId(); }
@@ -249,9 +264,9 @@ public JsonParser skipChildren() throws IOException {
249264
@Override public Object getTypeId() throws IOException { return delegate.getTypeId(); }
250265

251266
/*
252-
/**********************************************************
267+
/**********************************************************************
253268
/* Extended API
254-
/**********************************************************
269+
/**********************************************************************
255270
*/
256271

257272
/**

src/test/java/com/fasterxml/jackson/core/json/async/AsyncLocationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void testLocationOffsets() throws Exception
1818

1919
feeder.feedInput(input, 2, 3);
2020
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
21-
assertEquals(1, parser.getCurrentLocation().getByteOffset());
21+
assertEquals(1, parser.currentLocation().getByteOffset());
2222
assertEquals(1, parser.getTokenLocation().getByteOffset());
2323
assertEquals(1, parser.getCurrentLocation().getLineNr());
2424
assertEquals(1, parser.getTokenLocation().getLineNr());

0 commit comments

Comments
 (0)