Skip to content

Commit

Permalink
Fix #657: track nesting depth (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jun 21, 2024
1 parent d05688e commit afc3109
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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

0 comments on commit afc3109

Please sign in to comment.