我有一个包含 HashMap 的用户类,用于在两个自定义对象之间进行映射。
目前,每当我尝试在 mongodb 中保存一个用户时,我都会得到:
org.springframework.data.mapping.model.MappingException: Map key net.bigpoint.globalchat.models.keys.ProjectId@0 contains dots but no replacement was configured! Make sure map keys don't contain dots in the first place or configure an appropriate replacement!
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.potentiallyEscapeMapKey(MappingMongoConverter.java:548) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeMapInternal(MappingMongoConverter.java:512) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:385) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:346) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:335) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:173) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:335) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:307) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:272) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:73) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:717) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:707) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:703) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
at net.bigpoint.globalchat.hazelcast.MongoMapStore.store(MongoMapStore.java:81) [classes/:na]
at net.bigpoint.globalchat.hazelcast.MongoMapStore.store(MongoMapStore.java:1) [classes/:na]
at com.hazelcast.impl.concurrentmap.MapStoreWrapper.store(MapStoreWrapper.java:110) [hazelcast-2.0.2.jar:2.0.2]
at com.hazelcast.impl.ConcurrentMapManager$PutOperationHandler$PutStorer.doMapStoreOperation(ConcurrentMapManager.java:2736) [hazelcast-2.0.2.jar:2.0.2]
at com.hazelcast.impl.ConcurrentMapManager$AbstractMapStoreOperation.run(ConcurrentMapManager.java:3440) [hazelcast-2.0.2.jar:2.0.2]
at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212) [hazelcast-2.0.2.jar:2.0.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_04]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0_04]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_04]
在我看来,spring data 试图通过调用 toString 来序列化键,这是不可能反序列化的。
我已经有两个类的转换器,可以将实例转换为字符串,反之亦然,那么我的设置有什么问题?
编辑
由于某些讨厌的原因,MappingMongoConverter 类不使用转换器将键转换为可管理的东西,它只是使用 toString 将键转换为字符串并将字符串写入 DBObject。
在反序列化期间,字符串(这里作为对象处理)被转换为正确的键类型......