You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?)
The text was updated successfully, but these errors were encountered:
cowtowncoder
changed the title
Xml type resolver fails with NPE when property name is not specified in polymorphic serialization / deserialization
Xml type resolver fails with NPE when property name is not specified in polymorphic (de)serialization
Feb 11, 2021
If property name is not specified in polymorphic serialization, serialization fails as in following example
Produces
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?)
The text was updated successfully, but these errors were encountered: