0 Replies Latest reply on Jan 17, 2014 8:39 PM by csh

    JAXB: Map <xs:choice> to enum?




      I am trying to create a reasonable Java representation for this XML schema with JAXB:


      XEP-0107: User Mood


      Currently I have a new "empty" class like:


      @XmlElements({@XmlElement(name = "afraid", type = Afraid.class),

                  @XmlElement(name = "amazed", type = Amazed.class),

                  @XmlElement(name = "angry", type = Amazed.class),

                  @XmlElement(name = "amorous", type = Amazed.class),



      private Mood mood;


      public static final class Afraid extends Mood {


      public static final class Amazed extends Mood {



      This works, but I'd rather have an enum for that, so that users can use switch statements and have other comfort like code completion.

      Right now, they have to check for "if (mood instanceof Afraid)"


      Something like

      public enum Mood







      I know I could write a XmlAdapter, but then I still would have to write the whole classes AND the enum, so that's kind of duplicate.


      Any suggestions appreciated!