Skip to content

XML Empty tag to Empty string in the object during xml deserialization #162

@thefalconfeat

Description

@thefalconfeat

I am using jackson-dataformat-xml:2.6.2

If an empty tag is available in the xml and the respective field in the object is a string, it would be nice to have jackson populate the field with empty string rather than with null value.

Ex:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
        name = "",
        propOrder = {"first", "last"}
)
@XmlRootElement(
        name = "name"
)
public class Name {
private String first;
private String last;
}

xml:

<name>
<first>Ryan</first>
<last></last>
</name>

mapper creation:

new XmlMapper(XMLInputFactory2.newFactory(), XMLOutputFactory2.newFactory());

I would expect

Name name = mapper.readValue(xml, Name.class)

name.getLast().equals("") to return true but name.getLast() ends up being null.

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions