使用注释插件+ JAXB在x’字段’中插入自定义注释(在xsd – > java上)

使用案例:

想要将自定义注释插入到JAXB生成的java类中的字段中

问题:

使用Annotate插件+ JAXB [1],我能够成功插入自定义注释,但它们是在getter方法而不是字段中插入的。 然而,Morphia(mongo DB)注释(我实际上想要插入)只能注释java字段[2]。

我的测试xsd:

         

我的测试绑定xjb:

          

我生成的java片段:

  @XmlElement(required = true) protected String bar; @XmlElement(required = true) protected String hoobar; /** * Gets the value of the bar property. * * @return * possible object is * {@link String } * */ @SuppressWarnings({ }) public String getBar() { return bar; } 

如你所见,我想注释“bar”字段。 请指教。 如果需要,请求更多。

[1] 使用Jaxb或HyperJaxb生成@Indexed注释
[2]有关样本,请参阅Morphia的@Id注释

好的,你自己想通了。 使用来注释字段。 其他选择是:

  • 二传手
  • setter方法的参数
  • 吸气
  • 领域

请参阅文档 。

还有一件事:您需要将field属性放到外部标记中:

    

将它放在与annox:class属性相同的标记中可能不起作用。 发生在我身上。

Interesting Posts