I use maven with jaxb to make classes out from a schema. This schema has the following choice:
<tns:choice minOccurs="1" maxOccurs="unbounded">
<tns:element name="video_track" type="tcore:TTrack" minOccurs="1" maxOccurs="1"/>
<tns:element name="audio_track" type="tcore:TTrack" minOccurs="1" maxOccurs="1"/>
</tns:choice>
The meening is, we want a list with x
audiotracks
and/or x
videotracks
. We need at least one of an audio or a video track!
When I generate classes with this choice I get the following code:
@XmlElementRefs({
@XmlElementRef(name = "audio_track", type = JAXBElement.class),
@XmlElementRef(name = "video_track", type = JAXBElement.class)
})
protected List<JAXBElement<TTrack>> videoTrackOrAudioTrack;
This is not what we want. I think I loose informations because with the list of TTracks
I don't know if this is a video or an audio.
So what am I doing wrong here?
In maven I use org.jvnet.jaxb2.maven2 version 0.8.3
I resolved the problem with the simplify approach in a .xjb file:
To activate this plugin i changed my maven .pom file to:
This works perfect for me
No, you don't lose this information.
You get a list of
JAXBElement<TTrack>
. So you can checke.getName()
to find out if it is an audio or a video track.You can use my Simplify plugin to get audio and video tracks in separate properties. This is not exactly the model you have in your schema, but pretty close and much easier to use.
This customization:
Produces:
The reason you get this model is the
maxOccurs
on yourchoice
.Also consider using
xs:
orxsd:
prefixes for your XML Schema.