Skip to content

JAXB Annotate Plugin adds annoations to getters that return an enum type value #661

@kermit-the-frog

Description

@kermit-the-frog

I've got a problem with the JAXB Annotate Plugin and annotations for enum types. There are unwanted/unexpected annotations on getters that return an enum type value.

sample.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.example.org/sample"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.example.org/sample"
           elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:simpleType name="enumType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="VALUE_1"/>
            <xs:enumeration value="VALUE_2"/>
            <xs:enumeration value="VALUE_3"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="enumWithCommentType">
        <xs:simpleContent>
            <xs:extension base="enumType">
                <xs:attribute name="comment" type="xs:string" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>

sample.jxb:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               jaxb:version="3.0"
               xmlns:namespace="urn:jaxb.jvnet.org:plugin:namespace-prefix"
               xmlns:annox="urn:jaxb.jvnet.org:annox">
    <jaxb:bindings schemaLocation="sample.xsd">
        <jaxb:bindings>
            <namespace:prefix name="sample"/>
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:simpleType[@name='enumType']">
            <annox:annotate>
                <annox:annotate annox:class="org.example.annotation.SampleAnnotation"/>
            </annox:annotate>
            <jaxb:bindings multiple="true" node="xsd:restriction/xsd:enumeration">
                <annox:annotate>
                    <annox:annotate annox:class="java.lang.Deprecated"/>
                </annox:annotate>
            </jaxb:bindings>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

SampleAnnotation.java:

package org.example.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface SampleAnnotation
{
}

Resulting EnumType.java

//
// This file was generated by the Eclipse Implementation of JAXB, v4.0.6 
// See https://eclipse-ee4j.github.io/jaxb-ri 
// Any modifications to this file will be lost upon recompilation of the source schema. 
//


package org.example.sample;

import jakarta.xml.bind.annotation.XmlEnum;
import jakarta.xml.bind.annotation.XmlType;
import org.example.annotation.SampleAnnotation;


/**
 * 
 * 
 * &lt;p&gt;Java class for enumType&lt;/p&gt;.
 * 
 * &lt;p&gt;The following schema fragment specifies the expected content contained within this class.&lt;/p&gt;
 * &lt;pre&gt;{&#064;code
 * &lt;simpleType name="enumType"&gt;
 *   &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
 *     &lt;enumeration value="VALUE_1"/&gt;
 *     &lt;enumeration value="VALUE_2"/&gt;
 *     &lt;enumeration value="VALUE_3"/&gt;
 *   &lt;/restriction&gt;
 * &lt;/simpleType&gt;
 * }&lt;/pre&gt;
 * 
 */
@XmlType(name = "enumType")
@XmlEnum
@SampleAnnotation
public enum EnumType {

    VALUE_1,
    VALUE_2,
    VALUE_3;

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

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

}

Resulting EnumWithCommentType.java

//
// This file was generated by the Eclipse Implementation of JAXB, v4.0.6 
// See https://eclipse-ee4j.github.io/jaxb-ri 
// Any modifications to this file will be lost upon recompilation of the source schema. 
//


package org.example.sample;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlValue;
import org.example.annotation.SampleAnnotation;


/**
 * &lt;p&gt;Java class for enumWithCommentType complex type&lt;/p&gt;.
 * 
 * &lt;p&gt;The following schema fragment specifies the expected content contained within this class.&lt;/p&gt;
 * 
 * &lt;pre&gt;{&#064;code
 * &lt;complexType name="enumWithCommentType"&gt;
 *   &lt;simpleContent&gt;
 *     &lt;extension base="&lt;http://www.example.org/sample&gt;enumType"&gt;
 *       &lt;attribute name="comment" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
 *     &lt;/extension&gt;
 *   &lt;/simpleContent&gt;
 * &lt;/complexType&gt;
 * }&lt;/pre&gt;
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "enumWithCommentType", propOrder = {
    "value"
})
public class EnumWithCommentType {

    @XmlValue
    protected EnumType value;
    @XmlAttribute(name = "comment")
    protected String comment;

    /**
     * Gets the value of the value property.
     * 
     * @return
     *     possible object is
     *     {@link EnumType }
     *     
     */
    @SampleAnnotation
    public EnumType getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     * 
     * @param value
     *     allowed object is
     *     {@link EnumType }
     *     
     */
    public void setValue(EnumType value) {
        this.value = value;
    }

    /**
     * Gets the value of the comment property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getComment() {
        return comment;
    }

    /**
     * Sets the value of the comment property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setComment(String value) {
        this.comment = value;
    }

}

As you can see there are two occurences of @SampleAnnotation. One at the enum declaration in EnumType.java. An one at the getter public EnumType getValue() in EnumWithCommentType. The first one ist wanted/expected. The second one is unwanted/unexpected. Is this a bug or a configuration issue?

Kind regards,
Martin

Metadata

Metadata

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions