Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2
-
Component/s: Converters
-
Labels:None
Description
We've found it convenient to subclass ReflectionConverter to make changes to how some fields are marshalled and unmarshalled, while still using the default behavior for fields that don't need to be handled specially. However, it's not designed to be subclassed, so we ended up copying it into our code base.
After refactoring, here are the methods we found useful to override in the subclass. (I'm going by memory so this might not be slightly inaccurate.)
marshal(...)
visitFieldWhileMarshalling(Object source, HierarchicalStreamWriter writer,
MarshallingContext context,
String fieldName, Class fieldType, Object fieldValue)
unmarshal(...)
getFieldType(String xmlName)
visitFieldWhileUnmarshalling(Object result, Class fieldType,
String fieldName, Object fieldValue)
Also, we used these new methods but didn't need to override them:
writeXMLField(HierarchicalStreamWriter writer.
MarshallingContext context,
String fieldName, Object fieldValue)
readObjectField(Object source, String fieldName)
writeObjectField(Object dest, String fieldName, Object value)
Another detail I'd like to customize in the subclass is how Serialization methods are called. Essentially, I need to turn it off for certain classes. The obvious way is to allow the subclass to replace the
private SerializationMethodInvoker serializationMethodInvoker;
instance with a subclass (or maybe null?).
If you don't want to make that data member protected, then another possible way to support this would be with a
protected setSerializationMethodInvoker(SerializationMethodInvoker s);
method that the subclass could call.
(It is a long story why I cannot modify the serialization methods of the classes that I'm trying to serialize with XStream.)