java - MappingMongoConverter setMapKeyDotReplacement 不起作用

标签 java mongodb spring-boot spring-mongo

我的代码如下链接:
How to customize MappingMongoConverter (setMapKeyDotReplacement) in Spring-Boot without breaking the auto-configuration?

@Override
@Bean
public MappingMongoConverter mappingMongoConverter() throws Exception {
    DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(this.mongoDbFactory());
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, this.mongoMappingContext());
    converter.setCustomConversions(this.customConversions());
    converter.setMapKeyDotReplacement("_");
    return converter;
}

但是如果我尝试解析这个 JSON,即 Java JSONObject:

{
  "Dr.Web category": "known infection source",
  "categories": [
    "parked",
    "uncategorized"
  ]
}

这种异常总是会发生。

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.data.mapping.model.MappingException: Map key Dr.Web category contains dots but no replacement was configured! Make sure map keys don't contain dots in the first place or configure an appropriate replacement!

这很奇怪,因为 setMapKeyDotReplacement 实际上已设置,因此所有点都应该被替换。

您知道为什么此解决方案不起作用吗?

最佳答案

尝试在 return 语句之前包含 converter.afterPropertiesSet()

关于java - MappingMongoConverter setMapKeyDotReplacement 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44804985/

相关文章:

java - 找不到 onButtonClick 方法

javascript - MongoDB - 当嵌套键是变量时从对象中删除($unset)嵌套键

javascript - POST 返回值到 MongoDB onsubmit

spring - 如何将Spring Boot与Elasticsearch 7.3连接

java - "Cannot reference Employee.DEFAULT_GENDER before supertype constructor has been called"错误

java - 在 ubuntu 中从终端运行 jar 文件

java - 如何更改 Intellij 中 catch 语句的速度模板

mongodb - 如何从 mongodb 集合中读取特定的键值对

java - Springboot/Thymeleaf 在每个页面上从模型中检查当前用户

maven - io.fabric8:docker-maven-plugin:0.15.3:build失败