I would like to deserialize XML like the following using JAXB in Java:
This is called "mixed-mode content", and it's generally a pain in the ass to process.
The key in JAXB is to use the @XmlMixed
annotation - see javadoc.
Try something like this:
@XmlRootElement(name = "container")
static class Container {
@XmlMixed
@XmlElementRefs({
@XmlElementRef(name="foo", type=Foo.class)
})
List<?> content;
// ... plus the usual getters/setters
}
The content
list should contain a sequence of Foo
objects and Strings.