Java:jaxb-generics
如何让jaxb绑定到我的向量?我似乎无法让它绑定包含泛型的向量,因为它抱怨无法识别我的类“shape”或其任何子类型。。“[javax.xml.bind.JAXBException:class shape.shape或其任何超类在此上下文中都不为人所知。”Java:jaxb-generics,java,collections,jaxb,Java,Collections,Jaxb,如何让jaxb绑定到我的向量?我似乎无法让它绑定包含泛型的向量,因为它抱怨无法识别我的类“shape”或其任何子类型。。“[javax.xml.bind.JAXBException:class shape.shape或其任何超类在此上下文中都不为人所知。” 您应该在JAXBContext JAXBContext context = JAXBContext.newInstance(XVector.class, shape.class); (注意:按照惯例,Shape应该大写)谢谢你,我为没有大
您应该在
JAXBContext
JAXBContext context = JAXBContext.newInstance(XVector.class, shape.class);
(注意:按照惯例,
Shape
应该大写)谢谢你,我为没有大写我的班级感到羞耻。我还发现这个链接很有用,因为它清理了我的xml:
javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class shape.Rectangle nor any of its super class is known to this context.]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
public void saveFile(File filename) {
try {
FileOutputStream fout = new FileOutputStream(filename);
objs.setVector(objVec);
JAXBContext context = JAXBContext.newInstance(XVector.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(objs, fout);
fout.close();
} catch (JAXBException e) {
e.printStackTrace ();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
JAXBContext context = JAXBContext.newInstance(XVector.class, shape.class);