Я использую Spring Data Rest и мне нужно добавить пользовательский конвертер.У меня есть обходной путь, если я создаю @RepositoryRestController с @GetMapping (value = "/ search / findByFooId") ... Я переопределяю часть WebMVC.
1-й преобразователь:
public class DateToZonedDateTimeConverter implements Converter<Date, ZonedDateTime> {
@Override
public ZonedDateTime convert(final Date source) {
return source == null ? null : ofInstant(source.toInstant(), systemDefault());
}
}
2-й преобразователь:
public class ZonedDateTimeToDateConverter implements Converter<ZonedDateTime, Date> {
@Override
public Date convert(final ZonedDateTime source) {
return source == null ? null : Date.from(source.toInstant());
}
}
my Spring conf:
@Configuration
public class MyRepositoryRestConfigurerAdapter implements RepositoryRestConfigurer {
@Bean
public DateToZonedDateTimeConverter dateToZonedDateTimeConverter() {
return new DateToZonedDateTimeConverter();
}
@Bean
public ZonedDateTimeToDateConverter zonedDateTimeToDateConverter() {
return new ZonedDateTimeToDateConverter();
}
@Autowired
private CompanyRequestValidatorProxy companyRequestValidatorProxy;
public void configureConversionService(ConfigurableConversionService conversionService) {
System.out.println("--- debug ---");
conversionService.addConverter(dateToZonedDateTimeConverter());
conversionService.addConverter(zonedDateTimeToDateConverter());
}
public void configureRepositoryRestConfiguration(final RepositoryRestConfiguration config) {
config.exposeIdsFor(Foo.class);
}
}
Но у меня есть эта ошибка:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date]