I have this in my applicationContext.xml
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="mycompany.AsOfDateConverter"/>
<bean class="mycompany.CustomerConverter"/>
<bean class="mycompany.FooConverter"/>
</set>
</property>
</bean>
AsOfDateConverter looks like
public class AsOfDateConverter implements Converter<String, Date> {
@Override
public Date convert(String source) {
if(source == null) return new Date();
//... else parse date. not shown.
}
}
But Spring never picks up my DateConverter. Instead I get this
org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date]: no matching editors or conversion strategy found
at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:53)
at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:534)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:506)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:339)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:170)
Two solutions needed: a) Why isn't it using my converter? b) if date is null then can converter still call my converter?
I have all this working with PropertyEditors but wanted to port to Converters.
But I can't figure out why Spring MVC does not use my DateConverter. I have it implemented so that if source
}} instead of {{>}}. Even if the method parameter is Set.
– Ralph May 13 '11 at 09:13