简体   繁体   English

无论如何,是否只需要注释JAXB的字段

[英]Is there anyway to annotate only required fields for JAXB

I'm working on to convert Hibernate objects to XML using JAXB. 我正在使用JAXB将Hibernate对象转换为XML。 In our classes, we've around 50 fields from which I would need only 10 of them. 在我们的课程中,我们大约有50个字段,我只需要其中的10个。

Basically, I'd defined XmlType#propOrder with 2 properties. 基本上,我定义了具有2个属性的XmlType#propOrder。 JAXB complained that some public getters are not part of proporder. JAXB抱怨说,某些公共获取者不是命令的一部分。 I see that if I don't mark a property with either of XmlTransient/XmlElement, JAXB complains about it. 我看到,如果我不使用XmlTransient / XmlElement之一标记属性,JAXB会抱怨它。 Is there any way to skip writing 'XmlTransient' on every field? 有什么方法可以跳过在每个字段上写“ XmlTransient”的操作吗?

You can use @XmlAccessorType(XmlAccessType.NONE) so that only the annotated fields/properties are marshalled to XML. 您可以使用@XmlAccessorType(XmlAccessType.NONE)以便仅将带注释的字段/属性编组为XML。 JAXB does not require any annotations. JAXB不需要任何注释。 Annotations are only required to override the default behaviour. 仅需要注释才能覆盖默认行为。 What exceptions are you seeing? 您看到什么例外?

For More Information 欲获得更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM