Java: jaxb Generircs

Posted by Mac on Stack Overflow See other posts from Stack Overflow or by Mac
Published on 2010-03-16T04:42:29Z Indexed on 2010/03/16 6:16 UTC
Read the original article Hit count: 269

Filed under:
|
|

How can I get jaxb to bind to my Vector? I cannot seem to get it to bind a Vector that contains generics as it complains that it cannot recognize my class "shape" or any of its subtypes.. "[javax.xml.bind.JAXBException: class shape.shape nor any of its super class is known to this context.]"?

import java.util.Vector;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "XVector")
public class XVector<shape> {

    private Vector<shape> q;

    public XVector() {}

    @XmlElement(name = "q")
    public Vector<shape> getVector() {
        return q;
    }

    public void setVector(Vector<shape> q) {
        this.q = q;
    }
}

I get the following errors: 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);
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about jaxb