users@jaxb.java.net

Question about marshaling sub types

From: Pat Considine <Pat.Considine_at_FINEOS.com>
Date: Fri, 2 May 2008 11:07:10 +0100

Hi there

I am using Axis2 1.3 to generate JAXBRI (version 2.0.5) types to represent web services, using the WSDL2Java tool with JAXBRI as the databinding. I am having problems serializing sub types. I am not completely sure where the problems lies. It could be in Axis2 or the JAXBRI generated classes or even JAXBRI, hence this mail.

I have managed to isolate the behaviour to a working/non working case. For our failing service request definition we have:

  <xs:element name="CreateCompany">
  <xs:complexType>
         <xs:sequence>
             <xs:element name="manager" type="EmployeeIdentifier"/>
         </xs:sequence>
     </xs:complexType>
  </xs:element>

The JAXB class that represents the service request is generated as:
@XmlRootElement(name = "CreateCompany")
public class CreateCompany {
    @XmlElement(required = true)
    protected EmployeeIdentifier manager;
    .....
    .....
}

When we send a CoManagerIdentifier (which extends EmployeeIdentifier) the message on the wire contains only EmployeeIdentifier information (CoManagerIdentifier data is lost).

Now lets change the definition of the CreateCompany request. Let's make it nillable and optional:

  <xs:element name="CreateCompany">
  <xs:complexType>
         <xs:sequence>
             <xs:element minOccurs="0" nillable="true" name="manager" type="EmployeeIdentifier"/>
         </xs:sequence>
     </xs:complexType>
  </xs:element>

The generated JAXB class is :

@XmlRootElement(name = "CreateCompany")
public class CreateCompany {
    @XmlElementRef(name = "manager", type = JAXBElement.class)
    protected JAXBElement<EmployeeIdentifier> manager;
    .....
    .....
}

As you can see the generated class contains now contains a JAXBElement<EmployeeIdentifier> which works perfectly, marshaling the CoManagerIdentifier correctly and preserving CoManagerIdentifier data when putting the message on the wire.

There are 2 issues currently with the later, functioning, approach:
1) It only seems to work with one level of inheritance. If I had TeamLeaderIdentifier that extended CoManagerIdentifier, the TeamLeaderIdentifier does not seem to be marshalled correctly (behaviour simillar to the first approach, sub type data is lost). This is not a big issue for us at the moment.
2) The element data has to be nillable AND optional. Nillable is workaroundable for us, but optional is a show stopper as we need some of our inheritence hierarchy types (such as EmployeeIndentifier above) to be mandatory fields.

This looks to all intents and purposes a bug to me. Why do I have to make elements optional and nillable in order for subtypes to marshaled correctly? Also why does it only work to one level of inheritence? Are these bugs in JAXB or is it the AXIS2 generated JAXB classes that are causing the problem?

I still need to overcome problem 2) above. While the solution I have outlined works for certain scenarios, it does not work for mine (need to make elements optional). Anyone else overcome this problem, or have any ideas I can make it work?

Any ideas gratefully received



__________________________________________________________
FINEOS Corporation is the global brand name of FINEOS Corporation Limited and its affiliated group companies worldwide.
The information contained in this e-mail is confidential, may be privileged and is intended
only for the user of the recipient named above. If you are not the intended recipient or a
representative of the intended recipient, you have received this e-mail in error and must
not copy, use or disclose the contents of this e-mail to anybody else.

If you have received this e-mail in error, please notify the sender immediately by return
e-mail and permanently delete the copy you received. This e-mail has been swept for
computer viruses. However, you should carry out your own virus checks.
Registered in Ireland, No. 205721. http://www.FINEOS.com
__________________________________________________________