Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-1118

Custom converters not used for map keys

    XMLWordPrintable

    Details

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            w_c_smith Christopher Smith
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: