Skip to content

guard ToXmlGenerator cast in serializeWithType()/_serializeObjectId() for convertValue() - #905

Open
Sahana2524 wants to merge 1 commit into
FasterXML:3.xfrom
Sahana2524:serialize-with-type-tree-cast
Open

guard ToXmlGenerator cast in serializeWithType()/_serializeObjectId() for convertValue()#905
Sahana2524 wants to merge 1 commit into
FasterXML:3.xfrom
Sahana2524:serialize-with-type-tree-cast

Conversation

@Sahana2524

Copy link
Copy Markdown
Contributor

ClassCastException from XmlMapper.valueToTree() / convertValue() on any @JsonTypeInfo(include = As.PROPERTY) bean (the default inclusion):

java.lang.ClassCastException: class tools.jackson.databind.node.TreeBuildingGenerator
    cannot be cast to class tools.jackson.dataformat.xml.ser.ToXmlGenerator

serializeWithType() and _serializeObjectId() cast the generator to ToXmlGenerator to flag the type id as an attribute, but those two conversion entry points serialize into a TokenBuffer / tree generator rather than a ToXmlGenerator. The sibling methods _serializeProperties() and _serializePropertiesFiltered() in the same class already skip the XML-specific handling with an instanceof ToXmlGenerator guard (comment: "During 'convertValue()', need to skip"); these two type-id paths were the only ones missing it, so I added the same guard to both.

Real XML serialization is unchanged: the type id is still written as an attribute. Added a small regression test covering valueToTree, convertValue, and the unchanged XML output.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 74.20% 📈 +0.010%
Branches branches 68.98% 📈 +0.010%

Coverage data generated from JaCoCo test results

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.

1 participant