-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MappingMongoConverter
incorrectly processes an object property of type org.bson.Document
#3702
Comments
Thanks for reporting. I might be missing something here but unfortunately, I was not able to reproduce the issue based on the given information. |
Hi @christophstrobl, I'm sorry it wasn't clear, I tried to point to a specific location where is the problem. To save time, I attach a raw document [1] and screenshots from the debugging of tests with use of both versions of spring data mongodb. Screenshots description is bellow (and all important things are also highlighted on images):
If it is still not clear what the problem is, I will create a simplified example in my free time, but I hope, it won't be necessary. [1] https://drive.google.com/file/d/1lTF5p8mRjXbGB7pMzN7uib-Yq8pHAAl_/view |
Thanks @meloujir - I see - this seems to happen for |
MappingMongoConverter
incorrectly processes an object property of type org.bson.Document
Hi, we encountered a problem (originates from 3.1.5 > 3.2 update), which occurrs when a property (of some DBO entity) of type org.bson.Document is handled within MappingMongoConverter.ConversionContext#convert. MongoDB driver correctly returns a document, of which all inner object properties (fields) are of type org.bson.Document.
Then MappingMongoConverter comes into play (within process of populating fields , #populateProperties -> #readProperties). During that process, the property value of type org.bson.Document is incorrectly handled as a Map and all properties (fields) with an object value are converted to a LinkedHashMap. Later on, when we, within concrete context, try to convert that object of type org.bson.Document to certain class (using MongoTemplate#getConverter()#read(getEntityClass(), sourceObject), but it is not important), it leads to:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [...]
That error is only consequence of the way how the object of property of type org.bson.Document is treated. Yes, org.bson.Document is implementing a Map, but it should not be processed as a Map.
If we compare codes of version 3.1.5 and version 3.2.X
First, let's look at version 3.1.5:
MappingMongoConverter#readValue
Then MappingMongoConverter#read is called and the "if (Document.class.isAssignableFrom(rawType))" is chosen as a processing branch).
Now, let's look at MappingMongoConverter.ConversionContext#convert of version 3.2.X, more precisely 3.2.2:
I think, the right way is to let untouched inputs which should be treated (converted into) as org.bson.Document (suggested as typeHint param).
Can you please look at the problem? I believe I provided enough info, but if you need further details, do not hesitate to contact me.
Thank you for your cooperation.
Regards.
The text was updated successfully, but these errors were encountered: