google-code-export / morphia

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

Support replacing "untypedTypeEncoders" in DefaultConverters class #420

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)
Morphia version : 0.99
Mongo driver: 2.7.3

Issue description:
Currently, DefaultConverters class exposes two methods 
addConverter/removeConverter to allow adding/removing the converts, however in 
case of "untyped" converter (tc.getSupportedTypes() == null) these methods 
doesn't work as expected. 

Steps to reproduce:
I tried to replace the default EnumConverter with a custom Implementation (I 
extended the default EnumConverter implementation to support supplying a 
default value of the enum in case of decoding failure)
Here's a snippet of what i did:
morphia.getMapper().getConverters().removeConverter(new EnumConverter());
morphia.getMapper().getConverters().addConverter(new CustomEnumConverter());

Actual behavior:
While debugging i noticed that the enum decoding was done by EnumConverter, 
although this converter was supposed to be removed.

Expected behavior:
Enum decoding should be done by the new custom enum decoder.

Workaround:
I accessed by reflection the "untypedTypeEncoders" list in DefaultConverters 
instance, 
then replaced manually the EnumConverter with my CustomEnumConverter, and this 
did the trick for me. 

Original issue reported on code.google.com by o...@eyeviewdigital.com on 22 Jul 2012 at 10:29