Fix #37
diff --git a/release-notes/CREDITS b/release-notes/CREDITS
index 4e01f69..f07310b 100644
--- a/release-notes/CREDITS
+++ b/release-notes/CREDITS
@@ -70,3 +70,8 @@
Iskren Ivov Chernev (ichernev@github)
* Reported #213: Parser is sometimes wrong when using CANONICALIZE_FIELD_NAMES
(2.6.2)
+
+Michael Lehenbauer (mikelehen@github)
+ * Reported #37: JsonParser.getTokenLocation() doesn't update after field names
+ (2.7.0)
+
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 9e59eaf..88ba6a9 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -16,6 +16,8 @@
2.7.0 (not yet released)
+#37: JsonParser.getTokenLocation() doesn't update after field names
+ (reported by Michael L)
#198: Add back-references to `JsonParser` / `JsonGenerator` for low-level parsing issues
(via `JsonParseException`, `JsonGenerationException`)
#211: Typo of function name com.fasterxml.jackson.core.Version.isUknownVersion()
diff --git a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
index f416a60..c2c413f 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
@@ -619,20 +619,20 @@
if (_parsingContext.expectComma()) {
i = _skipComma(i);
}
- _updateLocation();
- /* And should we now have a name? Always true for
- * Object contexts, since the intermediate 'expect-value'
- * state is never retained.
+ /* And should we now have a name? Always true for Object contexts, since
+ * the intermediate 'expect-value' state is never retained.
*/
boolean inObject = _parsingContext.inObject();
if (inObject) {
- // First, field name itself:
+ // First, field name itself:
+ _updateNameLocation();
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
i = _skipColon();
}
+ _updateLocation();
// Ok: we must have a value... what is it?
@@ -771,13 +771,14 @@
if (_parsingContext.expectComma()) {
i = _skipComma(i);
}
- _updateLocation();
if (!_parsingContext.inObject()) {
+ _updateLocation();
_nextTokenNotInObject(i);
return false;
}
+ _updateNameLocation();
if (i == INT_QUOTE) {
// when doing literal match, must consider escaping:
char[] nameChars = sstr.asQuotedChars();
@@ -849,18 +850,19 @@
if (_parsingContext.expectComma()) {
i = _skipComma(i);
}
-
- _updateLocation();
if (!_parsingContext.inObject()) {
+ _updateLocation();
_nextTokenNotInObject(i);
return null;
}
+ _updateNameLocation();
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
i = _skipColon();
+ _updateLocation();
if (i == INT_QUOTE) {
_tokenIncomplete = true;
_nextToken = JsonToken.VALUE_STRING;
@@ -916,6 +918,7 @@
private final void _isNextTokenNameYes(int i) throws IOException
{
_currToken = JsonToken.FIELD_NAME;
+ _updateLocation();
switch (i) {
case '"':
@@ -966,6 +969,7 @@
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
i = _skipColon();
+ _updateLocation();
if (i == INT_QUOTE) {
_tokenIncomplete = true;
_nextToken = JsonToken.VALUE_STRING;
@@ -2670,9 +2674,12 @@
public JsonLocation getTokenLocation()
{
final Object src = _ioContext.getSourceReference();
+ if (_currToken == JsonToken.FIELD_NAME) {
+ return new JsonLocation(src,
+ -1L, _nameInputTotal, _nameInputRow, _tokenInputCol);
+ }
return new JsonLocation(src,
- -1L, getTokenCharacterOffset(),
- getTokenLineNr(),
+ -1L, _tokenInputTotal, _tokenInputRow,
getTokenColumnNr());
}
diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
index 6de5477..b0c007b 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
@@ -3619,8 +3619,7 @@
_nameInputTotal, -1L, _nameInputRow, _tokenInputCol);
}
return new JsonLocation(src,
- getTokenCharacterOffset(), -1L,
- getTokenLineNr(),
+ _tokenInputTotal, -1L, _tokenInputRow,
getTokenColumnNr());
}
diff --git a/src/test/java/com/fasterxml/jackson/failing/LocationInObjectTest.java b/src/test/java/com/fasterxml/jackson/core/json/LocationInObjectTest.java
similarity index 98%
rename from src/test/java/com/fasterxml/jackson/failing/LocationInObjectTest.java
rename to src/test/java/com/fasterxml/jackson/core/json/LocationInObjectTest.java
index 355d8bc..eb317d4 100644
--- a/src/test/java/com/fasterxml/jackson/failing/LocationInObjectTest.java
+++ b/src/test/java/com/fasterxml/jackson/core/json/LocationInObjectTest.java
@@ -1,4 +1,4 @@
-package com.fasterxml.jackson.failing;
+package com.fasterxml.jackson.core.json;
import com.fasterxml.jackson.core.*;