MappingMongoConverter setMapKeyDotReplacement不起作用

时间:2017-06-28 14:12:36

标签: 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,因此应该替换所有点。

您对此解决方案不起作用有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在return语句之前尝试包含+ echo 'myPassword = [*******]' myPassword = [*******]