springboot启动加载Converter报错

java写了一个string转LocalDateTime的Converter的方法,但是springboot启动报错:

Caused by: java.lang.IllegalArgumentException: Unable to determine source type and target type for your Converter [com.example.demo126.config.MappingConverterAdapter$$Lambda$522/1340928776]; does the class parameterize those types?

代码如下:

/**
* 日期参数接收转换器,将json字符串转为日期类型
*
* @return Converter
*/
@Bean
public Converter localDateTimeConverter() {
return source -> LocalDateTime.parse((String)source, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}

应该是无法获取参数:DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")的数据类型导致的,这是个实例化后才能用的方法,这样写得不到它返回的结果值的

@Bean
public Converter localDateTimeConverter() {
return source -> LocalDateTime.parse(source,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}

https://blog.csdn.net/qq_34631677/article/details/80118937