AttributeMapper makes use of getDelcaredField() which has very onerous requirements of field visibility and inherited fields.
Personally I find the whole approach taken by the AttributeMapper to be too heavy handed and would like to be able to easily specify that any type that can be handled by a SingleValueConverter should be written/read as an attribute.
Up until the 1.2..2-SNAPSHOT the following approach worked well, I simply added the following MapperWrapper and
class MyAttributeMapper extends MapperWrapper {
XStream xStream;
public MyAttributeMapper(Mapper wrapped, XStream xStream) {
super(wrapped);
this.xStream = xStream;
}
protected SingleValueConverter getLocalConverterFromItemType(Class type) {
Converter converter = xStream.getConverterLookup().lookupConverterForType(type);
if (converter != null && converter instanceof SingleValueConverter) {
return (SingleValueConverter)converter;
} else {
return null;
}
}
public SingleValueConverter getConverterFromItemType(Class type) {
return getLocalConverterFromItemType(type);
}
}
However testing with 1.2.2-SNAPSHOT our entire application bombs because of the added restriction introduced by the use of getDeclaredField() in AttributeMapper, as an example, see the following test :