I have been getting a “org.springframework.core.convert.ConverterNotFoundException” even though i have specified a class implementing the converter interface with the appropriate types which are java.util.Date and java.sql.Timestamp.
The code for converter is given below:
package com.application.applicationService.common;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.convert.converter.Converter;
import java.util.Date;
import java.sql.Timestamp;
public class DateToTimestampConverter implements Converter<Date, Timestamp> {
@Override
public Timestamp convert(@NotNull Date date) {
return new Timestamp(date.getTime());
}
}
I have also tried annotating this with @Component with no avail, anyways I then made a configuration class and extended it with WebMvcConfigurer as given below:
package com.application.applicationService.config;
import com.application.applicationService.common.DateToTimestampConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new DateToTimestampConverter());
}
}
The exact error was:
2024-06-18T18:56:38.033+05:30 ERROR 7676 --- [applicationService] [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [java.sql.Timestamp]
Any kind of help is appreciated and if you need anything else I will give it to you.
sohamsk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.