XML to JAVA with @XmlType instead of @XmlRootElement

Posted on by Kim

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

...

private AssessResponse loadOpaResponseFromXmlFile(String file) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(AssessResponse.class);
    InputStream is = getClass().getResourceAsStream(file);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    return unmarshaller.unmarshal(new StreamSource(is), AssessResponse.class).getValue();
}

----------------------

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AssessResponse", propOrder = {
    "versionInfo",
    "events",
    "globalInstance"})
public class AssessResponse
    implements Serializable
{

...

----------------------
<assess-response xmlns="http://oracle.com/determinations/server/12.2.1/rulebase/assess/types">
    <global-instance>
        <entity id="month" inferred="false">
            <instance id="xxx">

...

0 Responses to "XML to JAVA with @XmlType instead of @XmlRootElement":