I have to work with large XML documents which often handle missing attribute data incorrectly. Rather than just omitting the attribute with the missing data, the attribute is specified with an empty string value. This causes a problem when unmarshalling, since an empty string is a value.
For example, what should be
<SOME_ELEMENT attr1="someValue"/>
Is instead
<SOME_ELEMENT attr1="someValue" attr2="" attr3=""/>
I'm trying to come up with the "right" way of gracefully handling this poorly formed XML. The goal is to treat an attribute as if it were omitted when the attribute's value is a blank string, and a blank string is never a valid value for that attribute (e.g. Integers).
I'm currently using XMLAdapters to translate these empty strings to null (as suggested in this post) but this seems like the wrong solution. Many of the attributes in the documents I'm working are already using type adapters shared from other code and there doesn't appear to be a way to specify more than one XMLAdapter for an attribute.
Is there a standard way to handle this type of situation that I've just missed?
Thanks!
EDIT
I'm looking for a solution that does not require me to edit each of the various JAXB mapped classes, since there are several dozen all with the same needs. Ideally, a solution to this problem will allow me to specify a general policy for all attributes, and allow for specific overrides as necessary.