Marshal enum
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlRootElement; public class CardOutput { public static void main(String[] args) throws JAXBException { JAXBContext context = JAXBContext.newInstance(Card.class); context.createMarshaller().marshal(Card.CLUBS, System.out); } } @XmlRootElement @XmlEnum(String.class) enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
1. | Unmarshall with JAXB | ||
2. | Marshal object with JAXB | ||
3. | Create JAXBContext with custom object | ||
4. | Unmarshall to JAXB Element | ||
5. | Use Marshal Validation |