While trying to implement a workaround to accomplish
XSTR-405, I found no way for the code in a marshal method to access the annotations associated with the field/value that is being converted.
If this were possible, then it would be easy for developers to attach their own annotations and read them from the code that would convert a given class, without having to provide their own top-level converter.
It may seem like @XStreamConverter is an out here, but it offers no mechanism for providing per-use data values – and I don't think it could.
That is, you could not have (and would not want):
@XStreamConverter(class=MyClassConverter.class, customTweak=true)
MyClass fieldA;
@XStreamConverter(class=MyClassConverter.class, customTweak=false, tagName="foo")
MyClass fieldB;
But, if annotations were passed along, perhaps as part of the MarshallingContext, then I could write:
@XStreamConverter(MyClassConverter.class)
@MyAnno(customTweak=true)
MyClass fieldA;
@XStreamConverter(MyClassConverter.class)
@MyAnno(customTweak=true, tagName="foo")
MyClass fieldB;
It would also be very useful in the canConvert class to get access to this data. For compatibility, you could perhaps have:
interface ReflectiveConverter {
canConvert(Class clazz, AccessibleObject aobject);
}
and call that instead if the converter implements it.