Eliminate blank items when sorting with JAXB

Using JAXB (2), you can ensure that null values ​​are not sorted as () empty elements. For example,

@XmlRootElement(name = "root")
public class Root {
    @XmlElement(name = "name")
    protected String name;
}

Currently, if the name is null, I sort

<root>
  <name/>
</root>

I would like to create

<root>
</root>

instead.

+3
source share
1 answer

I think something was missing from you .. like a marshal, the string u passes should not be zero, since the string null is also a string .. therefore, in my opinion, u should pass an empty string, not null.

0
source

Source: https://habr.com/ru/post/1724886/


All Articles