本文介绍了MappingMongoConverter setMapKeyDotReplacement不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码链接后的代码:
My code following this link:
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:
But if I try parse this JSON, which is 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所以应该替换所有点。
This is strange cause setMapKeyDotReplacement is actually set so all dots should be replaced.
您对此解决方案不起作用有什么想法吗?
推荐答案
在return语句之前尝试包含 converter.afterPropertiesSet()
。
Try including converter.afterPropertiesSet()
before the return statement.
这篇关于MappingMongoConverter setMapKeyDotReplacement不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!