Details
Description
In the latest trunk code, it appears it's impossible to parse XML that contains unknown elements with predefined converters, such as <url>. I tried both ignoring them the old way, by overriding shouldSerializeMember with a "definedIn != Object.class" check, or the new way, calling xStream.ignoreUnknownElements().
This is a blocker for us, because there's no workaround.
Here's a self-contained unit test to reproduce this problem with XStream 1.4.5-20130321.143015-2:
public void testHandlingUnknownURLField() { final XStream xStream = new XStream(); xStream.ignoreUnknownElements(); xStream.processAnnotations(MyTestClass.class); final String xmlWithNewField = "<myTestClass><id>123</id><url>http://www.google.com</url></myTestClass>"; final MyTestClass c1 = (MyTestClass) xStream.fromXML(xmlWithNewField); assertNotNull(c1); } @XStreamAlias("myTestClass") public class MyTestClass implements Serializable { public MyTestClass() {} }
The bug appears to be introduced because of the apparent rewrite of AbstractReflectionConverter. In the following new code, CannotResolveClassException is thrown for the "id" field and type is assigned java.net.URL for the "url" field. It would seem that it should throw CannotResolveClassException for "url" too this is the only place that calls the handleUnknownField method.