JAXB JXC generates schema for enums regardless of @XmlTransient

966 Views Asked by At

Using the JXC schema generation ant task, I can't seem to get it to ignore an enum. I have several enums that are used internally to denote type or minor configuration values that are not relevant to the generated XML.

I can exclude the field using the enum as @XmlTransient to exclude it from the object's schema, but a simpleType descriptor is still generated for the enum!

Example:

public class CustomerType { 

    @XmlTransient    
    public enum IsolationLevel { ALL, SAME_TYPE, SELECTED }

    @XmlTransient
    private Long id;
    @XmlValue
    private String name;
    @XmlTransient
    private IsolationLevel isolation = IsolationLevel.ALL;
}

Generated Schema:

<xs:simpleType name="isolationLevel">
    <xs:restriction base="xs:string">
      <xs:enumeration value="ALL"/>
      <xs:enumeration value="SAME_TYPE"/>
      <xs:enumeration value="SELECTED"/>
    </xs:restriction>
</xs:simpleType>

Anyone have any ideas on how to make JXC ignore the enum? It's not being used by any XML mapped property or field, and the enum itself is marked @XmlTransient - why is it still part of my schema?

1

There are 1 best solutions below

0
On

I just ran into this as well and updated my pom to 2.2.11 and it's at least fixed for that version. The Jira bug mentioned in the comments also states it's been fixed in 2.2.5. In doing this I had to add the three dependencies as shown below:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.12</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>