JAXB Java and XSD mapping

In one of my projects, I use the JAXB2 marshaller, having the first contracted web service, I generate objects from an XML schema.

Everything works perfectly. But I have a "usability code" problem. Let me give you an example.

Scheme:

<xs:complexType name="personContractAlertListType">
    <xs:sequence>
        <xs:element ref="PersonContractAlert" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>


<xs:element name="PersonContractAlertsResponse">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="PersonContractAlertList"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

So, to access the list PersonContractAlerts, I need to call:

PersonContractAlertsResponse.getPersonContractAlertListType().getPersonContractAlert()

Which is longer.

My question is: how can I get rid of getPersonContractAlertListType()and go directly to:PersonContractAlertsResponse.getPersonContractAlert()

Since this shell element is valid only for XSD, I do not need this in my Java object.

In other words:

<Element1>
<Wrapper>
<Element2/>
</Wrapper>
</Element1>

And I want the following displayed in Java: Element1.getElement2()

JAXB. , . (, , ..), XSD (, ).

!

UPDATE:

:

https://jaxb.dev.java.net/guide/Using_different_datatypes.html

JAXB-.

+3

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


All Articles