问题
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