Hi,
that's something that is not really achievable. Have a look at the
following code fragment:
SearchPubsResponse entity =
(SearchPubsResponse) unmarshaller.unmarshal(new
InputSource(getClass().getResource(SAMPLE_FILE).toExternalForm()));
assertNotNull (entity);
assertNotNull(entity.getPublicationList());
assertFalse(entity.getPublicationList().isEmpty());
assertEquals(2, entity.getPublicationList().size());
As you can see, I am instructing Castor XML to unmarshal an instance of
SearchPubsresponse. Subsequently, I am accessing the collection of
PublicationImages via the collection property of that class.
I hope this helps.
Werner
Rachel Wilson wrote:
> Apologies. It's very late here and I've been looking at this for over
> 12 hours now. I had tried to simplify the code and take out names
> that only mean something to me and I noticed at the last second that
> i'd missed a few. I've corrected that in-situ below. Please forgive
> the multiple posts, even i'm annoyed at myself...
>
> This should be correct now
>
>
> * * * * *
>
> I have already posted a message "Mapping a List at root returns
> AnyNode objects instead of desired mapped object" and tried another
> tack only to be thwarted again unfortunately so I'm clearly doing
> something quite daft.
>
> I need to unmarshall a list of simple objects and this time I have
> created a wrapper java class to hold the list. But I can't seem to
> get the mapping right. (Hopefully it's a mistake that will help
> another beginner at least)
>
>
>
> Here is the XML I'd like to unmarshall:
>
> <search-publications-response item-count="2">
> <publication id="abc" />
> <publication id="def" />
> </search-publications-response>
>
>
> Here are my java classes:
>
> public class SearchPubsResponse
> {
> private List pubs;
>
> public List getPublicationList()
> {
> return pubs;
> }
>
> public void setPublicationList(List pubsList)
> {
> this.pubs = pubsList;
> }
> }
>
>
> 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):
>
>
> <mapping>
>
> <class name="qmul.qmrae.domain.SearchPubsResponse">
> <map-to xml="search-publications-response" />
> <field name="publicationList"
> type="qmul.qmrae.domain.PublicationImage" collection="collection"
> container="false">
> <bind-xml name="publication" />
> </field>
> </class>
>
>
> <class name="qmul.qmrae.domain.PublicationImage">
> <field name="articleId">
> <bind-xml name="id" node="attribute" />
> </field>
> </class>
>
> </mapping>
>
>
>
> And here is the unmarshalling java:
>
> Unmarshaller unmarshaller = new Unmarshaller();
>
> Mapping map = new Mapping();
> map.loadMapping(getClass().getResource( "/castor-mapping-pubs.xml"
> ));
> unmarshaller.setMapping(map);
>
> List pubs = (ArrayList)
> unmarshaller.unmarshal(fileReaderForMyXML);
>
> SearchPubsResponse searchPubsResponse = (SearchPubsResponse)
> unmarshaller.unmarshal(fileReader);
>
> // this step returns null
> List pubs = searchPubsResponse.getPublicationList();
>
>
>
> But in the logs I see the following when it gets to the unmarshalling
> step: org.exolab.castor.xml.UnmarshalHandler - unable to find
> FieldDescriptor for 'publication' in ClassDescriptor of
> search-publications-response - ignoring extra element.
>
> And nothing is returned in the List
>
> I expect what's causing this is at the root of my other problem but I
> just can't seem to unpick this. I've been following this example
> (http://castor.org/xml-mapping.html#4.-Usage-Pattern) and it looks the
> same to me :-s
>
>
> Hope you can help,
> Rachel
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email