MappingMongoConverter setMapKeyDotReplacement dont work

守給你的承諾、 提交于 2019-12-08 04:28:01

问题


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;
}

But if I try parse this JSON, which is Java JSONObject:

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

This exception always happens.

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!

This is strange cause setMapKeyDotReplacement is actually set so all dots should be replaced.

Do you have any ideas why this solution does not work?


回答1:


Try including converter.afterPropertiesSet() before the return statement.



来源:https://stackoverflow.com/questions/44804985/mappingmongoconverter-setmapkeydotreplacement-dont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!