What makes this use case odd is that you have inheritance in your XML schema between two types with mixed content. I think there is an XJC error (and possibly spec) here, and as suggested by Puce, you should enter the error for it at the following link:
XML Schema
schema.xsd
Here is a simpler XML schema that reproduces the same problem:
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified"> <complexType name="b" mixed="true"> <sequence> <element ref="tns:bb"/> </sequence> </complexType> <complexType name="c"> <complexContent mixed="true"> <extension base="tns:b"> <sequence> <element ref="tns:cc"/> </sequence> </extension> </complexContent> </complexType> <element name="bb" type="string"/> <element name="cc" type="string"/> </schema>
Invalid Java Model
IN
The class generated for type b is good.
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "b", propOrder = {"content"}) @XmlSeeAlso({C.class}) public class B { @XmlElementRef(name = "bb", namespace = "http://www.example.org/schema", type = JAXBElement.class) @XmlMixed protected List<Serializable> content; public List<Serializable> getContent() { if (content == null) { content = new ArrayList<Serializable>(); } return this.content; } }
FROM
The class generated for type c is incorrect, the question is, what should it be?
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "c") public class C extends B { }
Improved Java Model? - Option number 1
You can add property to class c . Then the question arises as to which of the mixed text belongs to a property inherited from b and which is part of the property defined in c .
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "c") public class C extends B { @XmlElementRef(name = "cc", namespace = "http://www.example.org/schema", type = JAXBElement.class) @XmlMixed protected List<Serializable> content2; }
Improved Java Model? - Option number 2
You can extend the property to b to know the link to an element from type c . This will allow XML to be processed correctly for types b and c , but will allow some documents that were not valid with respect to the XML schema.
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "b", propOrder = {"content"}) @XmlSeeAlso({C.class}) public class B { @XmlElementRefs({ @XmlElementRef(name = "bb", namespace = "http://www.example.org/schema", type = JAXBElement.class), @XmlElementRef(name = "cc", namespace = "http://www.example.org/schema", type = JAXBElement.class) }) @XmlMixed protected List<Serializable> content; public List<Serializable> getContent() { if (content == null) { content = new ArrayList<Serializable>(); } return this.content; } }