使用maven-jaxb2-plugin注释数据类型的所有元素

时间:2018-05-30 16:43:48

标签: maven-jaxb2-plugin

我的问题与以下帖子有关。 How to add Jackson annotations to POJO generated from XSD by JAXB/XJC? 有没有办法使用绑定文件使用maven-jaxb2-plugin为特定数据类型的所有元素添加注释?例如,使用@JsonFormat注释注释所有'xs:time'类型元素,而不是分别为每个特定元素添加注释。

1 个答案:

答案 0 :(得分:0)

感谢词典。在绑定文件中添加以下内容就可以了。

<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>

Xpath选择所有'date'元素,我们可以用一行注释它们。

相关问题