I ran into the same problem and found my solution here (without using annotations)
... you should at least correctly register the string in the [LocalDateTime] converter in your context so that Spring can use it to automatically do this for you every time you enter String as input and expect [LocalDateTime]. (A large number of converters have already been implemented using Spring and contain core.convert.support in the package, but none of them are associated with the [LocalDateTime] conversion)
So, in your case, you will do this:
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> { public LocalDateTime convert(String source) { DateTimeFormatter formatter = DateTimeFormatter.BASIC_ISO_DATE; return LocalDateTime.parse(source, formatter); } }
and then just register your bean:
<bean class="com.mycompany.mypackage.StringToLocalDateTimeConverter"/>
With annotations
add it to your ConversionService:
@Component public class SomeAmazingConversionService extends GenericConversionService { public SomeAmazingConversionService() { addConverter(new StringToLocalDateTimeConverter()); } }
and finally you must @Autowire in your ConversionService:
@Autowired private SomeAmazingConversionService someAmazingConversionService;
Read more about conversions with Spring (and formatting) on ββthis site . Be warned that he has a ton of advertising, but I definitely found it to be a useful site and a good introduction to this topic.
source share