1

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 ?

k31
  • 57
  • 4
  • as small addition: i tried all other possible values for @XmlAccessType but it doesn't get better – k31 Aug 28 '22 at 13:45
  • It is strange, that you have different outcomes from marshalling/schemagen... Are you sure, schemagen considers all (same) "locations/phases/pre-processors"? – xerx593 Aug 28 '22 at 13:58
  • there is something really strange going on: i added package-info.java class to specify target namespace but it's totally ignored by schemagen while jaxb marshaller/unmarshaller treat namespace well i use maven plugin ```xml org.codehaus.mojo jaxb2-maven-plugin 3.1.0 ``` and enabled debug level output to see what command line is used but all looks quite well: all files (including package-info.java) are specified as command line parameters – k31 Aug 28 '22 at 14:52
  • "however when i remove lombok \@Getter \@Setter and add methods manually then schema gets generated as expected" Seems to me that they are generated as elements, not attributes. – Roar S. Aug 28 '22 at 15:01
  • no, it has no effect on schemagen absolutely, also while when i generate schema through java code with JaxbContext, then it works nice, but i need to integrate xsd chema generation into my gitlab ci/cd pipeline which is the reason i am wasting time with schemagen and various maven plugins around it – k31 Aug 28 '22 at 22:45
  • do you find a solution to this apart from adding getters and setters manually? – David Nov 18 '22 at 14:12

0 Answers0