Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't spring using my Converter<String, Date>?
    primarykey
    data
    text
    <p>I have this in my applicationContext.xml</p> <pre><code>&lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /&gt; &lt;mvc:annotation-driven conversion-service="conversionService"/&gt; &lt;bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"&gt; &lt;property name="converters"&gt; &lt;set&gt; &lt;bean class="mycompany.AsOfDateConverter"/&gt; &lt;bean class="mycompany.CustomerConverter"/&gt; &lt;bean class="mycompany.FooConverter"/&gt; &lt;/set&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>AsOfDateConverter looks like</p> <pre><code>public class AsOfDateConverter implements Converter&lt;String, Date&gt; { @Override public Date convert(String source) { if(source == null) return new Date(); //... else parse date. not shown. } } </code></pre> <p>But Spring never picks up my DateConverter. Instead I get this </p> <pre><code>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) </code></pre> <p>Two solutions needed: a) Why isn't it using my converter? b) if date is null then can converter still call my converter?</p> <p>I have all this working with PropertyEditors but wanted to port to Converters. </p> <p>But I can't figure out why Spring MVC does not use my DateConverter. I have it implemented so that if source</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload