Xstream fails on extra xml element

View: New views
1 Messages — Rating Filter:   Alert me  

Xstream fails on extra xml element

by darniz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi users

i have an issue with xstream hopefully some one can answer this.
The issue I have is that if the xml response by a third party by chance have an element that we are not aware of xstream fails Lets take a simple case here
i have a customer class
public class Customer {
 String id;
 String name;
}
and the following unmarshalling works
    private void unmarshall(){
        String custXml ="<customer>\n" +
                "    <id>id1111</id>\n" +
                "    <name>jack</name>" +
                "  </customer>";
        XStream xstream =new XStream(new DomDriver());
        xstream.autodetectAnnotations(true);
        xstream.alias("customer", Customer.class);
        Customer customer = null;
        customer =(Customer) xstream.fromXML(custXml);
        System.out.println("done");
    }
The issue happens if i add an extra element in my xml for example if i add phone in my xml string
String custXml ="<customer>\n" +
                "    <id>id1111</id>\n" +
                "    <name>jack</name><phone>33333</phone>" +
                "  </customer>
i get an error message about not able to map phone.

For example when we use castor or jibx we can define mapping between xml element and our java object model and if there are some extra xml element in the message it wont fail and it gets ignored as far as i know.
Simialary for xstream too what ever property is defined in the class should gets populated and other xml element such as phone here should be ignored.

Any advice
darniz