In one of my projects I use JAXB2 marshaller, having a contract-first web service I generate the objects from a XML Schema.
Everything works just fine. But, I have a "code usability" issue. Let me give you an example.
Schema:
<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 in order to access the list of PersonContractAlerts
I have to call:
PersonContractAlertsResponse.getPersonContractAlertListType().getPersonContractAlert()
Which is kinda long.
My question is: How can I get rid of the getPersonContractAlertListType()
and go directly to: PersonContractAlertsResponse.getPersonContractAlert()
Because that wrapper element is really only for XSD, I don't need it in my Java object.
In other words have:
<Element1>
<Wrapper>
<Element2/>
</Wrapper>
</Element1>
And I want it in Java to map to: Element1.getElement2()
Maybe using JAXB adaptors. And remember I don't want to touch generated objects. This has to be done either in the marshaller settings (adaptar, interceptor, etc) or in the XSD (maybe there are some settings to manipulate).
Thanks a lot!
UPDATE:
I found a tutorial on some binding operations:
https://jaxb.dev.java.net/guide/Using_different_datatypes.html
I will research try using JAXB bindings.