简体   繁体   中英

Is there anyway to annotate only required fields for JAXB

I'm working on to convert Hibernate objects to XML using JAXB. In our classes, we've around 50 fields from which I would need only 10 of them.

Basically, I'd defined XmlType#propOrder with 2 properties. JAXB complained that some public getters are not part of proporder. I see that if I don't mark a property with either of XmlTransient/XmlElement, JAXB complains about it. Is there any way to skip writing 'XmlTransient' on every field?

You can use @XmlAccessorType(XmlAccessType.NONE) so that only the annotated fields/properties are marshalled to XML. JAXB does not require any annotations. Annotations are only required to override the default behaviour. What exceptions are you seeing?

For More Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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