google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Can not add new untyped TypeConverter to DefaultConverters #445

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Morphia 0.99

Whenever a new untypedTypeConverter is added to DefaultConverters it is added 
*after* the PassthroughConverter, meaning "getEncoder(Class c)" never finds the 
new converter but returns the PassthroughConverter instead. (Because it's 
isSupported() method returns true.)

Currently, to correct, you need to remove the PassthroughConverter, add the new 
converter, then re-add the PassthroughConverter. Given "getEncoder(Class c)" is 
private, the code looks a little messy:

DefaultConverters converters = morphia.getMapper().getConverters();

Method getEncoder = DefaultConverters.class.getDeclaredMethod("getEncoder", 
Class.class);
getEncoder.setAccessible(true);
TypeConverter passthroughTypeConverter = (TypeConverter) 
getEncoder.invoke(converters, PassthroughTypeConverter.class);

converters.removeConverter(passthroughTypeConverter);
converters.addConverter( ... new untyped converted ... );
converters.addConverter(passthroughTypeConverter);

Steve.

Original issue reported on code.google.com by steve.ey...@gmail.com on 22 Jan 2013 at 3:00