Skip to content
New issue

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

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

Already on GitHub? # to your account

Nesting depth in XmlReadContext is not incremented/decremented on JsonToken.START_OBJECT/JsonToken.END_OBJECT #657

Closed
AlexUg opened this issue Jun 20, 2024 · 5 comments
Labels
2.17 Issues planned at earliest for 2.17
Milestone

Comments

@AlexUg
Copy link

AlexUg commented Jun 20, 2024

This bug can be fixed with below patch (just like it is implemented in 'com.fasterxml.jackson.core.json.JsonReadContext'):

diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java
index bfef7d4d..8c57cfe4 100644
--- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java
+++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlReadContext.java
@@ -66,6 +66,7 @@ public final class XmlReadContext
         _lineNr = lineNr;
         _columnNr = colNr;
         _index = -1;
+        _nestingDepth = parent == null ? 0 : parent._nestingDepth + 1;
     }
 
     protected final void reset(int type, int lineNr, int colNr)

Sorry for not creating a pull request...

@cowtowncoder
Copy link
Member

@AlexUg Thank you for reporting this. Not a problem wrt PR, we can do that (plus specifically need to test this(.

@pjfanning
Copy link
Member

#609 is already open and describes why the nesting depth is not checked in jackson-dataformat-xml. TLDR is Woodstox can do the check.

@AlexUg
Copy link
Author

AlexUg commented Jun 20, 2024

#609 is already open and describes why the nesting depth is not checked in jackson-dataformat-xml. TLDR is Woodstox can do the check.

The "jackson-dataformat-xml" should not check nesting, but "jackson-dataformat-xml" should provide consumers with correct nesting information, as do the JSON and YAML parsers provided by "FasterXML" (to avoid violating interface specs - users expect correct information by calling 'parser.getParsingContext().getNestingDepth()' regardless of the parser type).

@cowtowncoder
Copy link
Member

True. There are some complexities here since nesting count will not necessarily be the same for logical content (JsonToken stream) as physical XML tokens -- this because there's a bit of translation going on.
But it should probably be more useful than not having nesting depth at all.

I am also not sure how easy it'd be to implement #609 over doing it on XML module side.

cowtowncoder added a commit that referenced this issue Jun 21, 2024
@cowtowncoder cowtowncoder changed the title Nesting depth in XmlReadContext is not incremented/decremented on JsonToken.START_OBJECT/JsonToken.END_OBJECT. Nesting depth in XmlReadContext is not incremented/decremented on JsonToken.START_OBJECT/JsonToken.END_OBJECT Jun 21, 2024
@cowtowncoder cowtowncoder added this to the 2.17.2 milestone Jun 21, 2024
@cowtowncoder cowtowncoder added the 2.17 Issues planned at earliest for 2.17 label Jun 21, 2024
@cowtowncoder
Copy link
Member

Fixing tracking part as suggested, via #658.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
2.17 Issues planned at earliest for 2.17
Projects
None yet
Development

No branches or pull requests

3 participants