How I can retrieve null value, when unmarshalling, if inside XML attribute value is empty ? Now I make inside my getters checking for null :
public String getLabel() {
if (label.isEmpty()) {
return null;
}
else {
return label;
}
}
But may be exist some other, more elegant way?
Thanks.
I think your XML looks more or less like this:
This, unfortunately, means, that you are passing an empty string.
If you want to pass
nullyou have two options:<myElement/>tag at all).xsi:nil.If using
xsi:nil, first you have to declare your xml element (in XSD file) asnilable, like this:Then, to pass the
nullvalue inside XML do this:or this:
This way, JAXB knows, that you are passing
nullinstead of an empty String.