Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.3.1
-
Fix Version/s: 1.4
-
Component/s: Converters
-
Labels:None
-
JDK version and platform:IcedTea 1.70 for Linux
Description
In my program, I serialize some objects which contain a field called "scenario". Depending on the case, I sometimes do not want this fiels to be unserialized. So, in these cases, I call xstream.omitField(MyClass.class, "scenario").
But the program still try to unserialize this field. I think that the problem comes from JavaBeanConverter.java, in fact, the shouldSerializeMember function is not called before the attempt to unserialize the object. I'm short on time so I can't make a minimal testcase before 2 or 3 days. Here is a proposed patch (I couldn't test it because I have some problems with apache Harmony) :
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final Object result = instantiateNewInstance(context); while (reader.hasMoreChildren()) { reader.moveDown(); String propertyName = mapper.realMember(result.getClass(), reader.getNodeName()); boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, result.getClass()); if (mapper.shouldSerializeMember(result.getClass(), propertyName)) { if (propertyExistsInClass) { Class type = determineType(reader, result, propertyName); Object value = context.convertAnother(result, type); beanProvider.writeProperty(result, propertyName, value); } else { throw new ConversionException("Property '" + propertyName + "' not defined in class " + result.getClass().getName()); } } reader.moveUp(); } return result; }
Issue Links
- relates to
-
XSTR-592 omitField only ignores field on deserialization if field non-existent
Resolved in HEAD.