Turn off CXF Aegis Inheritance support / Use Inheritance with DataContractSerializer?

259 views Asked by At

I use Apache CXF with Aegis data binding to provide a Java web service to a C# client. This works in principle very well. On the C# side, I would like to use the more limited DataContractSerializer, because it allows for collections instead of arrays. I understand using the DataContractSerializer limits the complexity of the Aegis-generated WSDL. Now I have a Java type that uses inheritance. Aegis is able to generate a WSDL that contains both the base and the derived type, but the DataContractSerializer does not seem to be able to understand this WSDL. SvcUtil falls back to the XmlSerializer, and my collections get ugly arrays.

I can imagine thee theoretical possibilities to deal with this issue:

  • Turn off Inheritance support with Aegis. This should cause the WSDL to contain only the derived types, containing each all of the base type properties.
  • Somehow make DataContractSerializer understand WSDL inheritance
  • Somehow make XmlSerializer use collections instead of arrays

I think the last two options are not possible, so I am stuck with the first one. How can I turn off Aegis inheritance?

Example WSDL fragment:

<xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://tables.basic.meona.de">
    <xsd:complexType abstract="true" name="BaseTreeNode">
        <xsd:sequence>
            <xsd:element minOccurs="0" name="active" type="xsd:boolean"/>
            <xsd:element minOccurs="0" name="category" type="xsd:boolean"/>
            <xsd:element minOccurs="0" name="name" nillable="true" type="xsd:string"/>
            <xsd:element minOccurs="0" name="sequenceNumber" nillable="true" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

<xsd:complexType name="EmergencyDiagnosis">
    <xsd:complexContent>
        <xsd:extension base="ns0:BaseTreeNode">
            <xsd:sequence>
                <xsd:element minOccurs="0" name="externalCode" nillable="true" type="xsd:string"/>
                <xsd:element minOccurs="0" name="favoriteDiagnosis" type="xsd:boolean"/>
                <xsd:element minOccurs="0" name="identifier" nillable="true" type="xsd:string"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

It seems former versions of Aegis did not generate the extension, so I am hoping it can be switched off: https://issues.apache.org/jira/browse/CXF-5176

1

There are 1 answers

0
Matthias Wuttke On

After reading the Aegis source code, I helped myself with the following hack:

public class AegisNonExtensionBeanType extends BeanType {

    @Override
    public BeanTypeInfo getTypeInfo() {
        BeanTypeInfo bti = super.getTypeInfo();
        bti.setExtension(false);
        bti.setExtensibleAttributes(false);
        bti.setExtensibleElements(false);
        return bti;
    }

    @Override
    public AegisType getSuperType() {
        return null;
    }

}

If I register this AegisType for my inherited beans, it works. Mustn't there be a better way?