Skip to content

Commit fede6c9

Browse files
committed
Fix #37
1 parent 8d200d4 commit fede6c9

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ Florian Schoppmann (fschopp@github@github)
7070
Iskren Ivov Chernev (ichernev@github)
7171
* Reported #213: Parser is sometimes wrong when using CANONICALIZE_FIELD_NAMES
7272
(2.6.2)
73+
74+
Michael Lehenbauer (mikelehen@github)
75+
* Reported #37: JsonParser.getTokenLocation() doesn't update after field names
76+
(2.7.0)
77+

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ JSON library.
1616

1717
2.7.0 (not yet released)
1818

19+
#37: JsonParser.getTokenLocation() doesn't update after field names
20+
(reported by Michael L)
1921
#198: Add back-references to `JsonParser` / `JsonGenerator` for low-level parsing issues
2022
(via `JsonParseException`, `JsonGenerationException`)
2123
#211: Typo of function name com.fasterxml.jackson.core.Version.isUknownVersion()

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -619,20 +619,20 @@ public final JsonToken nextToken() throws IOException
619619
if (_parsingContext.expectComma()) {
620620
i = _skipComma(i);
621621
}
622-
_updateLocation();
623622

624-
/* And should we now have a name? Always true for
625-
* Object contexts, since the intermediate 'expect-value'
626-
* state is never retained.
623+
/* And should we now have a name? Always true for Object contexts, since
624+
* the intermediate 'expect-value' state is never retained.
627625
*/
628626
boolean inObject = _parsingContext.inObject();
629627
if (inObject) {
630-
// First, field name itself:
628+
// First, field name itself:
629+
_updateNameLocation();
631630
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
632631
_parsingContext.setCurrentName(name);
633632
_currToken = JsonToken.FIELD_NAME;
634633
i = _skipColon();
635634
}
635+
_updateLocation();
636636

637637
// Ok: we must have a value... what is it?
638638

@@ -771,13 +771,14 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
771771
if (_parsingContext.expectComma()) {
772772
i = _skipComma(i);
773773
}
774-
_updateLocation();
775774

776775
if (!_parsingContext.inObject()) {
776+
_updateLocation();
777777
_nextTokenNotInObject(i);
778778
return false;
779779
}
780780

781+
_updateNameLocation();
781782
if (i == INT_QUOTE) {
782783
// when doing literal match, must consider escaping:
783784
char[] nameChars = sstr.asQuotedChars();
@@ -849,18 +850,19 @@ public String nextFieldName() throws IOException
849850
if (_parsingContext.expectComma()) {
850851
i = _skipComma(i);
851852
}
852-
853-
_updateLocation();
854853
if (!_parsingContext.inObject()) {
854+
_updateLocation();
855855
_nextTokenNotInObject(i);
856856
return null;
857857
}
858858

859+
_updateNameLocation();
859860
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
860861
_parsingContext.setCurrentName(name);
861862
_currToken = JsonToken.FIELD_NAME;
862863
i = _skipColon();
863864

865+
_updateLocation();
864866
if (i == INT_QUOTE) {
865867
_tokenIncomplete = true;
866868
_nextToken = JsonToken.VALUE_STRING;
@@ -916,6 +918,7 @@ public String nextFieldName() throws IOException
916918
private final void _isNextTokenNameYes(int i) throws IOException
917919
{
918920
_currToken = JsonToken.FIELD_NAME;
921+
_updateLocation();
919922

920923
switch (i) {
921924
case '"':
@@ -966,6 +969,7 @@ protected boolean _isNextTokenNameMaybe(int i, String nameToMatch) throws IOExce
966969
_parsingContext.setCurrentName(name);
967970
_currToken = JsonToken.FIELD_NAME;
968971
i = _skipColon();
972+
_updateLocation();
969973
if (i == INT_QUOTE) {
970974
_tokenIncomplete = true;
971975
_nextToken = JsonToken.VALUE_STRING;
@@ -2670,9 +2674,12 @@ protected byte[] _decodeBase64(Base64Variant b64variant) throws IOException
26702674
public JsonLocation getTokenLocation()
26712675
{
26722676
final Object src = _ioContext.getSourceReference();
2677+
if (_currToken == JsonToken.FIELD_NAME) {
2678+
return new JsonLocation(src,
2679+
-1L, _nameInputTotal, _nameInputRow, _tokenInputCol);
2680+
}
26732681
return new JsonLocation(src,
2674-
-1L, getTokenCharacterOffset(),
2675-
getTokenLineNr(),
2682+
-1L, _tokenInputTotal, _tokenInputRow,
26762683
getTokenColumnNr());
26772684
}
26782685

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,8 +3619,7 @@ public JsonLocation getTokenLocation()
36193619
_nameInputTotal, -1L, _nameInputRow, _tokenInputCol);
36203620
}
36213621
return new JsonLocation(src,
3622-
getTokenCharacterOffset(), -1L,
3623-
getTokenLineNr(),
3622+
_tokenInputTotal, -1L, _tokenInputRow,
36243623
getTokenColumnNr());
36253624
}
36263625

src/test/java/com/fasterxml/jackson/failing/LocationInObjectTest.java renamed to src/test/java/com/fasterxml/jackson/core/json/LocationInObjectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.core.json;
22

33
import com.fasterxml.jackson.core.*;
44

0 commit comments

Comments
 (0)