Affects: <2.1.8


I have a custom map implementation

class IdentityMap<T> : MutableMap<Identity, T>

And I have registered a

@WritingConverter
class IdentityWriteConverter : Converter<Identity, String>

and a

@ReadingConverter
class IdentityReadConverter : Converter<String, Identity>

so that Spring know how to handle the complex key type.

I use this in a @Document

@Document
class Cache(
    val id: String,
    val timestamps: IdentityMap<Instant> = emptyIdentityMap()
)

When saving this document, it generates the expected JSON, however when reading it, the MappingMongoConverter appears to be trying to use the Value Type (Instant in this case) to convert the Key (String) and ends up throwing a No converter found capable of converting from type String to type Instant ConverterNotFoundException here:

https://github.com/spring-projects/spring-data-mongodb/blob/6ab43c239191b8e48b257671ffbbb91259d5366d/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java#L1180

For whatever reason, the two lines a bit higher in the method

Class<?> rawKeyType = keyType != null ? keyType.getType() : null;
Class<?> rawValueType = valueType != null ? valueType.getType() : null;

are both pulling the same type out, Instant. Even though the key type of my map implementation is an Identity.

Comment From: sbrannen

This appears to be specific to Spring Data MongoDB, so please open an issue in their issue tracker.