mongodb/morphia — pull request #557 by pfuerholz (2013-11-27 13:48:17+00:00)
Title: Fixes / Should fix the issue 377

See http://code.google.com/p/morphia/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Stars%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=377

Encoding and decoding of entity properties happen not fully under same ruleset. As a matter of this reading data from MongoDB fails under following condition:
- Entity having a property of type 'Object' with @Serialized entity.
- If you save a simple object, e.g. a String or an Integer for this property the object is saved by means of the default/typed encoders. This means the value is saved as String / Integer in the DB.
- When reading the database the Morphia code tries to deserialize the object which fails with a MappingException. (Difference is here that DefaultEncoders#getEncoder with value=null is called. Thus it relies on the @Serialized annotation.)

Some points about my fix:
- If there is a property with @Serialized annotation, I prefer to have it saved as *serialized* object nevertheless Morphia would be able to map directly. This means @Serialized annotion should have priority.
- I am not sure if I found all necessary places where the fix is necessary.
- issue377.TestMapping contains some very simple test cases to check the fix.