OK,
I renamed the field and get/set methods, and am still getting the same
problem...?
Brennan
-----Original Message-----
From: Spies, Brennan
Sent: Wednesday, October 24, 2007 11:55 AM
To: users_at_jaxb.dev.java.net
Subject: Error with XML unmarshalling
I have a set of classes (POJOs) that define a workflow Job. The JobDefinition
has a collection of NodeDefinitions that define specific tasks to be done in
the workflow. I am using JAXB-2.1.5 to marshall and unmarshall to/from XML.
Works just fine until I do the unmarshalling from a test XML file...then I am
finding that my collection of Nodes is being populated by JAXB with
ElementNSImpl ?!
I can only assume that somehow JAXB is using reflection to get the setNodes()
method to populate this field in my JobDefinition (where Node is
com.ejgallo.worklow.Node):
private Collection<NodeDefinition<? extends Node>> nodes = new
ArrayList<NodeDefinition<? extends Node>>();
Running this JUnit method:
public void testJobDeserialization() {
System.out.println("Testing deserialization of Job...");
InputStream is = null;
try {
is =
this.getClass().getResourceAsStream("test-create.xml");
Unmarshaller unmarshaller = context.createUnmarshaller();
JobDefinition jobDef =
(JobDefinition)unmarshaller.unmarshal(is);
System.out.println("Job name: " + jobDef.getName());
Collection<NodeDefinition<? extends Node>> nodes =
jobDef.getNodes();
System.out.println("Iterating nodes...");
for(NodeDefinition<? extends Node> node : nodes) {
System.out.println(node.getName());
}
} catch (JAXBException e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if(is!=null) {
try {
is.close();
} catch (IOException e) {}
}
}
}
Gets the following error...
java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.dom.ElementNSImpl
Do I have to rename my field?
Brennan