Skip to content

Clear forced xsi:type attribute state in ToXmlGenerator.writeName - #909

Merged
cowtowncoder merged 7 commits into
FasterXML:3.xfrom
Sahana2524:xsi-type-attr-state-leak
Sep 23, 2026
Merged

cowtowncoder merged 7 commits into
FasterXML:3.xfrom
Sahana2524:xsi-type-attr-state-leak

Conversation

@Sahana2524

@Sahana2524 Sahana2524 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

writeName's synthetic xsi:type handling forces attribute mode and the XSI namespace onto the next value, and only the bean-serializer path clears it (by assigning the next name through setNextName). For a Map / JsonNode whose first key is xsi:type:

  • every following sibling becomes an xsi:-prefixed attribute instead of an element (e.g. a List-valued sibling becomes duplicate xsi:list attributes)
  • {"xsi:type":"A","type":"B"} emits a duplicate xsi:type attribute, so the module produces XML it can no longer read back
  • {"xsi:type":"T","nil":"true"} emits xsi:nil="true", so the whole document reads back as null

Clears the forced state on the next writeName for the content-driven case, reverting to the enclosing element name so the following sibling keeps the enclosing namespace (same as it would without the xsi:type key). The bean path already reset it via setNextName, so legitimate polymorphic output is unchanged.

Note: an xsi:type key that is not first (after child elements have been written, as is always the case for @JsonAnyGetter maps following regular properties) still fails with "Trying to write an attribute when there is no open start element"; that is a pre-existing limitation not addressed here.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 74.24% 📈 +0.050%
Branches branches 69.06% 📈 +0.090%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 75.19% 📈 +0.050%
Branches branches 69.78% 📈 +0.090%

Coverage data generated from JaCoCo test results

@cowtowncoder cowtowncoder changed the title clear forced xsi:type attribute state in ToXmlGenerator.writeName Clear forced xsi:type attribute state in ToXmlGenerator.writeName Sep 15, 2026
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 75.74% 📈 +0.050%
Branches branches 70.10% 📈 +0.090%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 75.74% 📈 +0.050%
Branches branches 70.10% 📈 +0.090%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 77.45% 📈 +0.050%
Branches branches 70.73% 📈 +0.080%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 77.45% 📈 +0.050%
Branches branches 70.73% 📈 +0.080%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 77.44% 📈 +0.040%
Branches branches 70.68% 📈 +0.030%

Coverage data generated from JaCoCo test results

@cowtowncoder
cowtowncoder merged commit 02d43d1 into FasterXML:3.x Sep 23, 2026
3 checks passed
@cowtowncoder

Copy link
Copy Markdown
Member

Thank you, @Sahana2524 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants