It seems that the type resolution is not working properly when having nested object composition with generic type.
Example of model: constructors, getters,... ommited
And create instance of Outer with
When we create an instance of Outer which has reference to instance of Generic whose generic type is MyEnum then if we save Outer instance using MongoTemplate it's persisted in db correctly converted to mongo's document.
But, when we try to read it from db it is mapped incorrectly back to Outer. Field myList in instance of Inner contains a List which contains instances of String, but field elem in instance of Inner is mapped correctly and it really contains an instance of MyEnum. Seems that problem is in MongoConverter. I'm attaching a simple project which is able to reproduce problem described above. In tests, I'm not actually storing an instance to mongo collection, but rather using only MongoConverter to convert an instance to Document and than back to Outer. I don't know if workaround for this cold be writing a custom Converter.
My workaround for this (in real project) was to manually convert a Document to some domain specific instance, but that is really annoying. I know that mapping from mongo types back can be tricky and sometimes type information is lost, but that is not case here. For comparison, I've tried Jackson's ObjectMapper to do serialization of instance of Outer to JSON string and than de-serialize JSON on back to Outer and it seems that Jackson resolves generic types correctly.