Suppose we have list of objects and we want to marshal them via JAXB:
...
@XmlElement(name = "value")
public List<Object> getValues() {
return values;
}
...
By default this would produce following output:
...
<value xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">123</value>
<value xsi:type="xs:boolean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">true</value>
<value xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">Lorem ipsum</value>
...
Pay attention that standard schema URIs duplicated for each list item - quite inefficient if we have lot of items. This issue can be addressed with package-level annotations. Add package-info.java file to the package that contains your domain classes:
@XmlSchema(xmlns = {@XmlNs(prefix = "xsi", namespaceURI = XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI),
@XmlNs(prefix = "xs", namespaceURI = XMLConstants.W3C_XML_SCHEMA_NS_URI)})
package com.jaspersoft.ji.jaxrs.query;

import javax.xml.XMLConstants;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;
Now schema URIs will be specified only once, in the root element:
<myContainerTag xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
<value xsi:type="xs:int">123</value>
<value xsi:type="xs:boolean">true</value>
<value xsi:type="xs:string">Lorem ipsum</value>
...