XStream not ignoring Unknown Elements when using JavaBeanConverter

537 views
Skip to first unread message

Paul Ramsden

unread,
Sep 22, 2015, 4:25:45 AM9/22/15
to XStream User
I am using XStream 1.4.7 to handle de/serialisation of POJOs. As the project develops, I will need to add new features and therefore new class fields. I would like old versions of the app to handle these changes gracefully and to ignore unknown tags.

xs = new XStream();
xs.setMode(XStream.NO_REFERENCES);
xs.ignoreUnknownElements();
xs.registerConverter(new JavaBeanConverter(xs.getMapper(),
new TransientRespectingBeanProvider()), XStream.PRIORITY_VERY_LOW);

Yesterday I added a String field to one of my classes and serialised it. An older version of the app was not able to deserialise the xml.

com.thoughtworks.xstream.converters.ConversionException: No field 'materialNrVersion' found in class 'com.company.ProjectConfiguration' : No field 'materialNrVersion' found in class 'com.company.ProjectConfiguration'
---- Debugging information ----
message : No field 'materialNrVersion' found in class 'com.company.ProjectConfiguration'
cause-exception : com.thoughtworks.xstream.converters.reflection.MissingFieldException
cause-message : No field 'materialNrVersion' found in class 'com.company.ProjectConfiguration'
class : com.company.ProjectConfiguration
required-type : com.company.ProjectConfiguration
converter-type : com.thoughtworks.xstream.converters.javabean.JavaBeanConverter
line number : 192
version : 1.4.7

Should I be doing this a different way?

UPDATE If I comment out the registerConverter call, then the unknown fields are ignored. The JavaBeanConverter seems to be affecting the way the ignoreUnknownElements is handled. The TransientRespectingBeanProvider is intended to ignore properties which have a @Transientannotation.

Can anyone suggest a solution or workaround? An alternative approach to the @Transient issue?

Jörg Schaible

unread,
Sep 22, 2015, 7:12:36 AM9/22/15
to xstrea...@googlegroups.com
Hi Paul,
Some features of XStream are not available, simply because they are based on
reflection. Since field names and property names of a bean do not have to
match, those features are typically not available for types handled with the
JavaBeanConverter (each converter has to respect the settings on its own).

However, the configuration of the fields to ignore is not directly
reflection-based and support could be added to JavaBeanConverter. Please
open an issue at GitHub. Patches welcome ;-)

Cheers,
Jörg

Reply all
Reply to author
Forward
0 new messages