Derived Types as Part of XML Messages

We have created a couple of XML schemas where the field is of an abstract type, but at runtime the messsage will contain the type derived from that abstract type. Java code handles correctly by default, but I am puzzled if and how this will handle XML-unmarshalling. Will Java <=> XML generated by JAXB be able to handle this out of the box or do we need to do some binding?

+3


source to share


1 answer


This is a somewhat abstract question, so here's a somewhat abstract answer.

JAXB will most likely be able to handle this:



  • The specific type can be specified via xsi:type

    . Please see this post by Blais Doughan. This method allows you to use a specific type at runtime. You will get the same item, but xsi:type

    specify a specific type. For example, you can get<geometry xsi:type="polygonType" .../>

  • Sometimes inheritance is modeled using lookup groups, see @XmlElementDecl

    substitutionHeadName

    / substitutionHeadNamespace

    . In this case, you can replace the abstract element with a specific element. For example, an abstract _Geometry

    element with a specific element Polygon

    .

JAXB supports both methods, but through different constructs.

+2


source







All Articles