【问题标题】:annotate all elements of a data type using maven-jaxb2-plugin使用 maven-jaxb2-plugin 注释数据类型的所有元素
【发布时间】:2018-05-30 16:43:48
【问题描述】:

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

【问题讨论】:

  • jaxb:bindings 与选择所有此类元素的 XPath 一起使用。还要将multiple="true" 添加到jaxb:bindings
  • 成功了。谢谢。
  • 请回答您自己的问题并展示它是如何工作的。这将有助于未来的读者(你会得到一些代表点)。

标签: maven-jaxb2-plugin


【解决方案1】:

感谢词典。绑定文件中的以下添加可以解决问题。

<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 选择所有“日期”元素,我们可以用一行注释它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多