I've got this autogenerated code from the xsd (extracted from CAURequest.java):

@XmlRootElement(name = "CAURequest")
public class CAURequest {
@XmlElement(name = "PF")
protected CAURequest.PF pf;
@XmlElement(name = "DI")
protected CAURequest.DI di;
@XmlElement(name = "PG")
protected CAURequest.PG pg;
@XmlElement(name = "I", required = true)
protected List<CAURequest.I> i;

@XmlAnyElement(lax = true)
protected List<Object> any;

Now I need to use the "any" element, added from this other autogenerated code (extracted from EuriscIVA.java):

@XmlRootElement(name = "EuriscIVA")
public class EuriscIVA {
@XmlElement(name = "PF")
protected EuriscIVA.PF pf;
@XmlElement(name = "DI")
protected EuriscIVA.DI di;
@XmlElement(name = "PG")
protected EuriscIVA.PG pg;
@XmlAttribute(name = "ACE")
protected String ace;
@XmlAttribute(name = "DAA", required = true)
protected int daa;
@XmlAttribute(name = "DC", required = true)
protected int dc;
@XmlAttribute(name = "DS", required = true)
protected int ds;
@XmlAttribute(name = "DR", required = true)
protected int dr;

this is the piece of code where I merge these things:

PF nodoPF = new PF();   //element of CAURequest
nodoPF.setN(...);
nodoPF.setC(...);
[...]
bM1.setPF(nodoPF);      // bM1 is a CAURequest object

bM2.setPF(new EuriscIVA.PF());  // bM2 is a EuriscIVA object. it also has a "PF" element
bM2.getPF().setPCF("1");        // element of EuriscIVA

bM1.getAny().add(bM2);          

Till here everything works fine (I see it in the debug variables window).

After that I made:

    // creo il document
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document swb = db.newDocument();

    JAXBContext contextObj = JAXBContext.newInstance(CAURequest.class);
    Marshaller marshallerObj = contextObj.createMarshaller();
    marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    // marshaling
    marshallerObj.marshal(bM1, swb); // HERE GIVES THE ERROR

  javax.xml.bind.JAXBException: class it.bccsi.sicra.pef.crif.generatedschema.eurisc.EuriscIVA nor any of its super class is known to this context.

EuriscIVA is the second class that should be added to the first class.

What I'm doing wrong?

1

There are 1 answers

0
Francesco On

It was so simple...

JAXBContext contextObj = JAXBContext.newInstance(CAURequest.class, EuriscIVA.class);