[XML]
I need to unmarshall a list of simple objects. I'd like iterate through them
without having to create a wrapper java class merely to hold the list of
objects in which I'm interested.
Very similar to this poster:
http://www.mail-archive.com/[email protected]/msg02830.html
And working almost exactly like this example:
http://www.castor.org/how-to-map-a-list-at-root.html
However after the unmarshalling step when I try and loop through what I would
expect to be PublicationImage objects in an ArrayList but instead I'm getting
org.exolab.castor.types.AnyNode objects and therefore fails with a
ClassCastException.
I've tried all sorts of variations using location attributes in the mapping
file or trying to map-to different nodes but it always falls over at the same
step for the same reason. Here is a simplified version of what I have at the
moment...
Here is the XML I'd like to unmarshall:
Here is my class:
public class PublicationImage
{
private String articleId;
public String getArticleId()
{
return articleId;
}
public void setArticleId(String articleId)
{
this.articleId = articleId;
}
}
here is my mapping file (castor-mapping-pubs.xml):
And here is the unmarshalling java
Unmarshaller unmarshaller = new Unmarshaller(ArrayList.class);
Mapping map = new Mapping();
map.loadMapping(getClass().getResource( "/castor-mapping-pubs.xml" ));
unmarshaller.setMapping(map);
List pubs = (ArrayList) unmarshaller.unmarshal(fileReaderForMyXML);
Iterator pubsIt = pubs.iterator();
while (pubsIt.hasNext())
{
// this step is failing with a ClassCastException
PublistsOutputImage pub = (PublistsOutputImage) pubsIt.next();
}
I'm using version 1.3 of the jars
I cannot change the XML structure that i'm unmarshalling because it is a
response from a third party API.
I hope you can point me at my no doubt silly mistake
Rachel
_________________________________________________________________
Windows Live Messenger: Happy 10-Year Anniversary—get free winks and emoticons.
http://clk.atdmt.com/UKM/go/157562755/direct/01/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email