MongoDB No converter found capable of converting from type [java.lang.String] to type [java.time.LocalDateTime]
This solved the problem:
@Configuration
public class MongoConfiguration extends AbstractMongoConfiguration {
@Value("${spring.data.mongodb.database:test}")
private String database;
@Value("${spring.data.mongodb.host:localhost}:${spring.data.mongodb.port:27017}")
private String host;
@Autowired
private MappingMongoConverter mongoConverter;
// Converts . into a mongo friendly char
@PostConstruct
public void setUpMongoEscapeCharacterConversion() {
mongoConverter.setMapKeyDotReplacement("_");
}
@Override
protected String getDatabaseName() {
return database;
}
@Override
public Mongo mongo() throws Exception {
return new MongoClient(host);
}
@Bean
@Override
public CustomConversions customConversions() {
List<Converter<?, ?>> converterList = new ArrayList<Converter<?, ?>>();
converterList.add(new MongoLocalDateTimeFromStringConverter());
return new CustomConversions(converterList);
}
private static final class MongoLocalDateTimeFromStringConverter implements Converter<String, LocalDateTime> {
@Override
public LocalDateTime convert(String source) {
return source == null ? null : LocalDateTime.parse(source);
}
}
}