JAXB 任何元素添加编组错误 javax.xml.bind.JAXBException: 类 *** 或它的任何超类在



我从xsd中得到了这个自动生成的代码(摘自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;

现在我需要使用从其他自动生成的代码(提取自 EuriscIVA.java(添加的 "any" 元素:

@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;

这是我合并这些内容的代码段:

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);          

到目前为止一切正常(我在调试变量窗口中看到它(。

之后,我做了:

// 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是应该添加到第一类中的第二类。

我做错了什么?

太简单了...

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

相关内容

最新更新