users@jaxb.java.net

Error with XML unmarshalling

From: Spies, Brennan <Brennan.Spies_at_ejgallo.com>
Date: Wed, 24 Oct 2007 11:55:01 -0700

I have a set of classes (POJOs) that define a workflow Job. The Job has a
collection of Nodes 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