I'm deserizaling the MPEG Dash schema using jaxb2.
The generation of the Java classes works great, however, part of the information in the Dash manifest is lost. Namely, data contained inside the ContentProtection
element. Which looks something like this:
<ContentProtection schemeIdUri="urn:uuid:SomeIdHash" value="PlayReady">
<cenc:pssh>Base64EncodedBlob</cenc:pssh>
<mspr:pro>Base64EncodedBlob</mspr:pro>
</ContentProtection>
The default schema throws the inner fields into a DescriptorType
class with @XmlAnyElement
annotation that results in a List of objects that looks like this:
[[cenc:pssh: null], [mspr:pro: null]]
To attempt to fix the issue, I created my own jxb binding for the ContentProtection
like so:
<jxb:bindings node="//xs:complexType[@name='RepresentationBaseType']/xs:sequence/xs:element[@name='ContentProtection']">
<jxb:class ref="com.jmeter.protocol.dash.sampler.ContentProtection"/>
</jxb:bindings>
However, I'm not closer to getting the Base64EncodedBlob
information contained within. I'm not sure how to setup my annotations in the custom class to construct the list correctly. This is what I've tried.
//@XmlAnyElement(lax = true) //[[cenc:pssh: null], [mspr:pro: null]]
// @XmlJavaTypeAdapter(Pssh.class) //DOESNT WORK
// @XmlValue //Empty List???
// @XmlSchemaType(name = "pssh")
// @XmlElementRef(name = "pssh") //Not matching annotations
// @XmlElement(name = "enc:pssh") //Not matching annotations
protected List<Pssh> pssh;
public List<Pssh> getPssh() {
if (pssh == null) {
pssh = new ArrayList<Pssh>();
}
return this.pssh;
}
My Pssh class looks like:
package com.jmeter.protocol.dash.sampler;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "enc:pssh")
// @XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "cenc:pssh")
public class Pssh {
// @XmlValue
//@XmlElement
private String psshValue;
public String getPsshValue() {
return psshValue;
}
public void setPsshValue(String psshValue) {
this.psshValue = psshValue;
}
}
What can I do to make the List of Pssh
objects get constructed with the base64 blobs instead of null?
I recommend you enable XML schema validation on your JAXB unmarshaller. It usually tells you all the wrong things in the XML input that are preventing JAXB to unmarshall properly (like unexpected XML content that it does not know which Java class(es) to map it to). It will make debugging this kind of stuff easier. For example, I don't see any namespace declaration for prefixes cenc
and mspr
in your XML. If undeclared/undefined, JAXB does not know their XML type definitions. You will need to provide schemas for them as well for full schema validation. Although full schema validation is not mandatory with processContents="lax"
, it helps detect potential deserialization issues early on. Besides, in general, it is always safer to validate input.
Last but not least, make sure the JAXBContext - from which you create the Unmarshaller - is made aware of the extra JAXB-annotated classes that you want to bind cenc:pssh
and msgpr:pro
(their XML types actually) to. Like:
JAXBContext.newInstance(Pssh.class,Pro.class,...);