jaxb schemagen ignores @XmlAttribute when used with lombok

315 Views Asked by At

say i have a class that must be marshalled/unmarshalled using jaxb

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "myEvent")
@SuperBuilder()
@NoArgsConstructor
@Getter
@Setter
public class MyEvent extends SomeBaseClass {
    @XmlAttribute(required = true)
    private long processId;
    @XmlAttribute(required = false)
    private Long groupId;
}

judging from @XmlAccessorType(XmlAccessType.NONE) description it should

None of the fields or properties is bound to XML unless they are specifically annotated with some of the JAXB annotations.

so i tried to serialize and deserialize my java object and all worked as charm:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:message xmlns:ns2="my-namespace">
  <ns2:myEvent processId="1" groupId="2"/>
</ns2:message>

the problem is that when i try to generate xsd schema such properties are totally ignored

  <xs:complexType name="myEvent">
    <xs:complexContent>
      <xs:extension base="someBaseClass">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

however when i remove lombok @Getter @Setter and add methods manually then schema gets generated as expected

  <xs:complexType name="myEvent">
    <xs:complexContent>
      <xs:extension base="someBaseClass">
        <xs:sequence>
          <xs:element name="groupId" type="xs:long" minOccurs="0"/>
          <xs:element name="processId" type="xs:long"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

one would say not a big deal, but i am used to lombok fluent api for getters/setters and don't want to loose it, not even speaking that code gets less clear and cluttered with boilerplate code

plus i see such behavior illogical as there is no requirement on presence getters/setters in source code mentioned anywhere in documentation.

any ideas ?

0

There are 0 best solutions below