Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #657: track nesting depth #658

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Project: jackson-dataformat-xml

No changes since 2.17

2.17.2 (not yet released)

#657: Nesting depth in `XmlReadContext` is not incremented/decremented on
JsonToken.START_OBJECT/JsonToken.END_OBJECT
(reported by @AlexUg)

2.17.1 (04-May-2024)

#646: Deserializing fails when using builder classes with `Iterable` Collection setters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public XmlReadContext(XmlReadContext parent, int type, int lineNr, int colNr)
_lineNr = lineNr;
_columnNr = colNr;
_index = -1;
_nestingDepth = parent == null ? 0 : parent._nestingDepth + 1;
}

protected final void reset(int type, int lineNr, int colNr)
Expand All @@ -77,6 +78,7 @@ protected final void reset(int type, int lineNr, int colNr)
_currentName = null;
_currentValue = null;
_namesToWrap = null;
// _nestingDepth fine as is, same level for reuse
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ public void testSimplest() throws Exception
// -> "{\"leaf\":\"abc\"}"

try (JsonParser p = _xmlMapper.createParser(XML)) {
assertEquals(0, p.getParsingContext().getNestingDepth());
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertEquals(1, p.getParsingContext().getNestingDepth());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("leaf", p.currentName());
assertEquals(1, p.getParsingContext().getNestingDepth());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("abc", p.getText());
assertEquals(1, p.getParsingContext().getNestingDepth());
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertEquals(0, p.getParsingContext().getNestingDepth());
assertNull(p.nextToken());
assertEquals(0, p.getParsingContext().getNestingDepth());
}
}

Expand Down