简体   繁体   中英

Jaxb Element Attribute Choice

is there any trick to have two element attributes defined, which excludes each other (similar like choice) ? I know to make it on elements but not on attributes.

@XmlAttribute(name="firstName") 
private String firstName ;
@XmlAttribute(name="lastName") 
private String lastName ;

For example, either element firstName="" or element lastName="" is valid, but not element firstName="" lastName=""

Is this possible ?

There is no attribute choice. You'll need to convert them to full-fledged elements.

If the value mapped with @XmlAttribute is null then it won't be marshaled to XML. You can combine this with some of your own custom logic to get the result you are looking for.

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