java - JAXB not creating member variables and getters and setters -
i trying generate java classes form xsd schema , using jaxb. part when run process generate classes works. there few classes member variable, getters , , setters not generated. here have
file ns2.xsd
<xs:element name="observation" type="ns2:observationtype" substitutiongroup="ns1:_metadata"/> <xs:complextype name="observationtype" mixed="true"> <xs:complexcontent mixed="true"> <xs:extension base="ns1:abstracttype"> <xs:sequence> <xs:element ref="ns2:identifier"/> </xs:sequence> </xs:extension> </xs:complexcontent> </xs:complextype>
file ns3.xsd
<xs:element name="observation" type="ns3:observationtype" substitutiongroup="ns2:observation"/> <xs:complextype name="observationtype" mixed="true"> <xs:annotation> <xs:documentation>this extends ns2:observationtype </xs:documentation> </xs:annotation> <xs:complexcontent mixed="true"> <xs:extension base="ns2:observationtype"> <xs:sequence> <xs:element ref="ns3:deliveryinfo" minoccurs="0"/> </xs:sequence> </xs:extension> </xs:complexcontent> </xs:complextype>
this creates empty class
package mypackage.ns3; import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmltype; /** * extends ns2:observationtype * * <p>java class observationtype complex type. * * <p>the following schema fragment specifies expected content contained within class. * * <pre> * <complextype name="observationtype"> * <complexcontent> * <extension base="{http://earth.esa.int/ns2}observationtype"> * <sequence> * <element ref="{http://earth.esa.int/ns3}deliveryinfo" minoccurs="0"/> * </sequence> * </extension> * </complexcontent> * </complextype> * </pre> * * */ @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "observationtype") public class observationtype extends mypackage.ns2.observationtype { }
my question why not creating required member variable , setters , getters? there wrong schema or there limitation on jaxb create missing information form complex types use extensions different files? thank in advance. or comments appreciated.
what makes use case odd have inheritance in xml schema between 2 types mixed content. think there xjc (and possibly spec) bug here, , suggested puce should enter bug @ following link:
xml schema
schema.xsd
here simpler xml schema reproduces same issue:
<?xml version="1.0" encoding="utf-8"?> <schema xmlns="http://www.w3.org/2001/xmlschema" targetnamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementformdefault="qualified"> <complextype name="b" mixed="true"> <sequence> <element ref="tns:bb"/> </sequence> </complextype> <complextype name="c"> <complexcontent mixed="true"> <extension base="tns:b"> <sequence> <element ref="tns:cc"/> </sequence> </extension> </complexcontent> </complextype> <element name="bb" type="string"/> <element name="cc" type="string"/> </schema>
incorrect java model
b
the class generated b
type fine.
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "b", proporder = {"content"}) @xmlseealso({c.class}) public class b { @xmlelementref(name = "bb", namespace = "http://www.example.org/schema", type = jaxbelement.class) @xmlmixed protected list<serializable> content; public list<serializable> getcontent() { if (content == null) { content = new arraylist<serializable>(); } return this.content; } }
c
the class generated c
type wrong, question should be?
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "c") public class c extends b { }
better java model? - option #1
you add property c
class. question comes down of mixed text goes on property inherited b
, goes in property defined on c
.
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "c") public class c extends b { @xmlelementref(name = "cc", namespace = "http://www.example.org/schema", type = jaxbelement.class) @xmlmixed protected list<serializable> content2; }
better java model? - option #2
you extend property on b
aware of element reference c
type. allow handle xml correctly b
, c
types allows documents weren't valid against xml schema.
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "b", proporder = {"content"}) @xmlseealso({c.class}) public class b { @xmlelementrefs({ @xmlelementref(name = "bb", namespace = "http://www.example.org/schema", type = jaxbelement.class), @xmlelementref(name = "cc", namespace = "http://www.example.org/schema", type = jaxbelement.class) }) @xmlmixed protected list<serializable> content; public list<serializable> getcontent() { if (content == null) { content = new arraylist<serializable>(); } return this.content; } }
Comments
Post a Comment