javaxmljaxbdate-formatxmladapter

How to apply a @XmlJavaTypeAdapter rule to all fields of a specific type at once in JAXB?


I want to change the way XML date format is written, but I don't want to put annotations in every getter of the entire project.

Is there a way to set the XmlAdapter globally to all fields of a specific type? Or at least in each class and not in each method.

Obs: My models aren't generated, they are hand written.

Thanks!


Solution

  • You can set the @XmlJavaTypeAdapter at the package level and have it apply to all mapped fields/properties in domain classes in that package. This is done on a special package-info class.