I am trying to make JAXB do not marshal empty tags when string is empty.
I can make it by creating XmlAdapter where insted empty string null would be returned. But in that way, I will have to annotate each attribute with this adapter.
Is there any way to make it more global?
EclipseLink JAXB (MOXy) will let you specify the
XmlAdapterforjava.lang.Stringat the package level (I’m the MOXy tech lead):package-info
StringAdapter
Root
jaxb.properties
To use MOXy as your JAXB provider you need to include a file named
jaxb.propertiesin the same package as your model classes with the following entry:Demo
Note
Due to what I feel is a bug in the JAXB reference implementation, the following exception is thrown if you use the version of JAXB included in Java SE 6: