users@jaxb.java.net

JAXB 2.0 Unmarshal NullPointerException

From: Scott Allan <sallan1000_at_aol.com>
Date: Thu, 21 Jul 2005 13:09:18 -0500

I'm using JAXB-2.0EA. I'm trying to marshal/unmarshal an object as an
org.w3c.dom.Document. Marshaling works to System.out and there is no
error thrown marshaling to the Document, but I get a
NullPointerException when I try to unmarshal it. Any idea what I'm doing
wrong? This worked ok in JAXB 1.0.


ObjectFactory objFactory = new ObjectFactory();
MyJAXBDocument myJAXBDocument = objFactory.createMyJAXBDocument();
MyJAXBType myJAXB = objFactory.createMyJAXBType();
myJAXBDocument.setMyJAXB(myJAXB);
myJAXB.setMyElement("test");

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
org.w3c.dom.Element root = doc.getElement();

JAXBContext jc =
JAXBContext.newInstance(com.mysite.jaxb.ObjectFactory.class);
Marshaller m = jc.createMarshaller();
m.setProperty("com.sun.xml.bind.xmlDeclaration",Boolean.FALSE);
m.marshal(myJAXBDocument, System.out); /* this works */
m.marshal(myJAXBDocument, doc);


Unmarshaller u = jc.createUnmarshaller();
Object o = u.unmarshal(root); /* this gives null pointer */
m.marshal(o, System.out);
o = u.unmarshal(doc); /* this also does not work */
m.marshal(o, System.out);


 

  _____

<< ella for Spam Control >> has removed 23708 Spam messages and set
aside 2 Newsletters for me
You can use it too - and it's FREE! www.ellaforspam.com