user8844941
user8844941

Reputation: 13

annotate all elements of a data type using maven-jaxb2-plugin

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

Answers (1)

user8844941
user8844941

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

Related Questions