mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
105 stars 76 forks source link

No XML files generated from Enums by schemagen goal #167

Closed BudWhiteStudying closed 3 years ago

BudWhiteStudying commented 3 years ago

In a sample Java project (JDK8) containing a single Java enum file, the execution of the schemagen goal results in an empty schemas folder (save for the META-INF/sun-jaxb.episode file).

@XmlEnum
@XmlType(
        propOrder = {"value"},
        name = "SampleEnum",
        namespace = "http://wow/my/namespace"
)
@XmlAccessorType(XmlAccessType.FIELD)
public enum SampleEnum {
    FOO("foo", 3),
    BAR("bar", 5);

    @XmlAttribute(name = "value", required = true)
    public final String value;

    @XmlAttribute(name = "value", required = true)
    public final int code;
    SampleEnum(String value, int code) {
        this.value = value;
        this.code = code;
    }
    public static SampleEnum fromValue(String v){return valueOf(v);}
}

Is the schemagen goal expected to build XSD from enums?

BudWhiteStudying commented 3 years ago

Ok it turns out the goal will not generate anything from sheer enums, but will work as expected if a "collector" class listing the enums as its properties is processed together with the enums e.g. adding this class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType
public class CollectorClass {
    @XmlAttribute(name = "SampleEnum")
    private SampleEnum sampleEnum;
}

will result in a schema for the class and a schema for the enum.