Når du bruger Spring Data MongoDB får du en instans af:org.springframework.data.mongodb.core.convert.MappingMongoConverter
der har mapKeyDotReplacement
sat til null som standard - det er derfor, du får en undtagelse.
Du skal enten oprette din egen forekomst af org.springframework.data.mongodb.core.convert.MappingMongoConverter
eller bare modificere eksisterende instans ved hjælp af dens provider-indstillermetode:
/**
* Configure the characters dots potentially contained in a {@link Map} shall be replaced with. By default we don't do
* any translation but rather reject a {@link Map} with keys containing dots causing the conversion for the entire
* object to fail. If further customization of the translation is needed, have a look at
* {@link #potentiallyEscapeMapKey(String)} as well as {@link #potentiallyUnescapeMapKey(String)}.
*
* @param mapKeyDotReplacement the mapKeyDotReplacement to set
*/
public void setMapKeyDotReplacement(String mapKeyDotReplacement) {
this.mapKeyDotReplacement = mapKeyDotReplacement;
}
I MongoDB behandles prik altid som et specialtegn, så at undgå det vil højst sandsynligt spare dig for anden hovedpine i fremtiden.
EDIT:For at tilsidesætte standard MappingMongoConverter
tilføje følgende bønnedeklaration:
@Bean
public MappingMongoConverter mongoConverter(MongoDbFactory mongoFactory) throws Exception {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory);
MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
mongoConverter.setMapKeyDotReplacement(".");
return mongoConverter;
}