Reputation: 13
My question is related to the following post. How to add Jackson annotations to POJO generated from XSD by JAXB/XJC? Is there a way to add annotations using maven-jaxb2-plugin for all elements of a specific data type using bindings file? For example, annotate all 'xs:time' type elements with @JsonFormat annotation instead of adding annotation to each specific element separately.
Upvotes: 1
Views: 1250
Reputation: 13
Thanks lexicore. The following addition in bindings file did the trick.
<jaxb:bindings schemaLocation="Schema.xsd" node="//xs:element[@type='xs:date']" multiple="true">
<annox:annotate target="field">@com.fasterxml.jackson.annotation.JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone="GMT")</annox:annotate>
</jaxb:bindings>
The Xpath selects all the 'date' elements and we can annotate them with a single line.
Upvotes: 0