-
-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
qoomon/maven-git-versioning-extension
#99Milestone
Description
If property name is not specified in polymorphic serialization, serialization fails as in following example
public class XmlPolyTest {
@JsonTypeInfo(use = DEDUCTION)
@JsonSubTypes(@JsonSubTypes.Type(Child1.class))
public interface Parent {}
public static class Child1 implements Parent {
private final String property1;
@JsonCreator(mode = Mode.PROPERTIES)
public Child1(String property1) {
this.property1 = property1;
}
public String getProperty1() {
return property1;
}
}
@Test
void jacksonXmlTest() throws JsonProcessingException {
var xmlMapper = new XmlMapper();
assertThat(xmlMapper.writeValueAsString(new Child1("value1")))
.contains("<property1>value1</property1>");
}
}
Produces
java.lang.NullPointerException
at com.fasterxml.jackson.dataformat.xml.util.StaxUtil.sanitizeXmlTypeName(StaxUtil.java:81)
at com.fasterxml.jackson.dataformat.xml.XmlTypeResolverBuilder.typeProperty(XmlTypeResolverBuilder.java:45)
at com.fasterxml.jackson.dataformat.xml.XmlTypeResolverBuilder.typeProperty(XmlTypeResolverBuilder.java:25)
at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector._findTypeResolver(JacksonAnnotationIntrospector.java:1517)
Workaround is to specify dummy property name (which is ignored in use=DEDUCTION), but there should be probably nullness check (probably in XmlTypeResolverBuilder#typeProperty around call to StaxUtil.sanitizeXmlTypeName?)
Metadata
Metadata
Assignees
Labels
No labels