我的代码跟随此链接:

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()

09-26 02:55