Saat menggunakan Spring Data MongoDB Anda mendapatkan instance dari:org.springframework.data.mongodb.core.convert.MappingMongoConverter
yang memiliki mapKeyDotReplacement
setel ke null secara default - itulah sebabnya Anda mendapatkan pengecualian.
Anda harus membuat instance org.springframework.data.mongodb.core.convert.MappingMongoConverter
Anda sendiri atau cukup ubah instance yang ada menggunakan metode penyetel penyedianya:
/**
* 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;
}
Di MongoDB, titik selalu diperlakukan sebagai karakter khusus sehingga menghindarinya kemungkinan besar akan menyelamatkan Anda dari sakit kepala lain di masa mendatang.
EDIT:Untuk mengganti MappingMongoConverter
default tambahkan deklarasi kacang berikut:
@Bean
public MappingMongoConverter mongoConverter(MongoDbFactory mongoFactory) throws Exception {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory);
MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
mongoConverter.setMapKeyDotReplacement(".");
return mongoConverter;
}