Comments in Enums imported from wsimport XSD

Is there a way to get comments from XSD to Java code using wsimport? For example, I have an XSD file

<!-- Enumerace /model/user/UserLevel.java -->
<xs:simpleType name="userLevel">
    <xs:restriction base="xs:string">
        <!-- basic user -->
        <xs:enumeration value="BASE"/>
        <!-- team leader -->
        <xs:enumeration value="TL"/>
        <!-- section leader -->
        <xs:enumeration value="SL"/>
    </xs:restriction>
</xs:simpleType>

and I want my generated class enum enum to look something like this:

@XmlType(name = "userLevel")
@XmlEnum
public enum UserLevel {
    /**
     * basic user
     */
    BASE,
    /**
     * team leader
     */
    TL,
    /**
     * section leader
     */
    SL;
}

Is this even possible in the first contract (for example, java code generated from XSD)?

+3
source share
1 answer

Ok, I found a solution, this is on XSD:

<xs:simpleType name="MyEnum">
    <xs:restriction base="xs:string">
        <xs:enumeration value="STANDARD">
            <xs:annotation>
                <xs:documentation>
                    This is a comment.
                </xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

creates a Java enumeration such as:

@XmlType(name = "MyEnum")
@XmlEnum
public enum MyEnum {


    /**
     * 
     *                         This is a comment.
     *                     
     * 
     */
    STANDARD,

    public String value() {
        return name();
    }

    public static MyEnum fromValue(String v) {
        return valueOf(v);
    }

}

The only problem is that the xs: document documentation does not ignore spaces, so there are many spaces in the comments.

+1
source

Source: https://habr.com/ru/post/1791430/


All Articles