Skip to content

Commit

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

Please sign in to comment.