Skip to content
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

Custom converters not used for map keys [DATAMONGO-1118] #2034

Closed
spring-projects-issues opened this issue Dec 11, 2014 · 2 comments
Closed

Custom converters not used for map keys [DATAMONGO-1118] #2034

spring-projects-issues opened this issue Dec 11, 2014 · 2 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Dec 11, 2014

Christopher Smith opened DATAMONGO-1118 and commented

I have an enum with rather long names and shorter per-value "tags" that I want to use for serialization. I've implemented a Converter pair that maps the values back and forth. They work properly when saving a Set of the enum.

However, when saving a Map<MyEnum,?>, the converter method is skipped; the enum's name is still used as the map key saved to Mongo. This would be frustrating but work-aroundable, but the proper converter is applied on reads. This means that when I save an object with a non-empty map and immediately attempt to read it, I get an exception when calling the read converter (since it's being supplied an invalid argument).

The problem appears to be at MappingMongoConverter:644, where the conversion service is explicitly skipped. This means that converters are applied to all types on read, and to all instances except map keys on write


Affects: 1.6.1 (Evans SR1)

Referenced from: pull request #260, and commits 00e1ebb, 79fdf44, d5afdf7, b8e9ff1, a1febdb, a3e4f44, 2b40a6e, c353e02, ce5fe50, dd32479, d8bb644, 4a7a485

Backported to: 1.6.2 (Evans SR2), 1.5.5 (Dijkstra SR5)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 19, 2014

Christoph Strobl commented

Thanks Christopher Smith for reporting. Confirmed, registered converts are called for Map keys on read but not on write

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 6, 2015

Christopher Smith commented

I'm glad to see a fix, but I disagree with both the priority and text changes. The problem is that this introduced data corruption because of inconsistent treatment of the map keys. Not using converters at all would have been a minor bug, but using them for read but not for write meant that data written by the repository would immediately cause exceptions when trying to read it back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants