spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

MappingMongoConverter cast map's key to String, but ask for any Object, so why?

Open netbeansuser2019 opened this issue 4 years ago • 6 comments

Lines:

https://github.com/spring-projects/spring-data-mongodb/blob/45971b212c12c67e4233d1b139de06ba088e18ee/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java#L1073

https://github.com/spring-projects/spring-data-mongodb/blob/45971b212c12c67e4233d1b139de06ba088e18ee/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java#L1074

Why it is checked for String and then ask for conversion for Object and cast to String?

netbeansuser2019 avatar Aug 11 '21 05:08 netbeansuser2019

Sorry it took so long to get back to you. Thanks for bringing this to our attention! Do you want to submit a PR or should we take care of this?

christophstrobl avatar Sep 28 '21 08:09 christophstrobl

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Oct 05 '21 08:10 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Oct 12 '21 08:10 spring-projects-issues

HI @christophstrobl to understand the issue, the problem is that we're re computing same thing again right?, of checking for possible converter

so instead of doing the ternary operator we can do

		String convertedSimpleWrite = (String) getPotentiallyConvertedSimpleWrite(key, String.class);
		return Optional.ofNullable(convertedSimpleWrite).orElse(key.toString());

right?

thekaleidoscope avatar Oct 12 '21 08:10 thekaleidoscope

@christophstrobl @mp911de is this still relevent? if so, can you please let me know on the above query?

thekaleidoscope avatar Oct 18 '21 12:10 thekaleidoscope

@christophstrobl Hi, just flagging this again in case you missed it

thekaleidoscope avatar Nov 20 '21 13:11 thekaleidoscope