How do I mark fields as required/optional when reading XML with MOXy?
问题 Having a trivial code like this: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) class A { @XmlPath("B/text()") private String b; @XmlPath("C/text()") private Integer c; ... } It works absolutely fine as long as I have apt values in my XML. I'd like to mark the field c as required, so MOXy throw every time I try to read the document where c is either not set, or invalid. What's the easiest solution? Update: Setting default values will also do. 回答1: EclipseLink JAXB (MOXy) or any JAXB