question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jlouscommented, Jan 3, 2017

Any idea when the PR might be merged if approved?

0reactions
itisvamsicommented, Oct 17, 2018

Is there any fix for this which is available?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Deserialize Xml with empty elements - Stack Overflow
I used this approach. First it removes the null or empty elements from the XML file using LINQ and then it deserialize the...
Read more >
differentiating between null and empty string in a xml ... - MSDN
Hi guys,. I have a xml which i Deserialize, using XMLSerializer class, into a custom object. One property of the custom object is...
Read more >
[Solved] Deserializing empty XML tags in C# with enumerations
I've been playing with the XmlIgnore attribute and created another member to import the value for the empty tag as a String, and...
Read more >
[Solved]-Xml Serialization - Render Empty Element-C#
The solution to this was to create a PropertyNameSpecified property that the serializer uses to determine whether to serialize the property or not....
Read more >
Jackson XML ignore empty element
Deserialization from XML. Jackson also allows us to read the contents of an XML file and deserialize the XML String back into a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found