You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define a JavaBean with a List property that uses a type conversion annotation e.g. @DateTimeFormat(iso=Iso.DATE) List<Date> dates;
Attempt to bind element values e.g. dates[0]=2010-07-04&dates[1]=2011-07-04. Instead of succeeding, the following binding error will be returned:
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'javaBean' on field 'dates[0]': rejected value [2010-07-04]; codes [typeMismatch.javaBean.dates[0],typeMismatch.javaBean.dates,typeMismatch.dates[0],typeMismatch.dates,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [javaBean.dates[0],dates[0]]; arguments []; default message [dates[0]]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dates[0]'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2010-07-04" from type 'java.lang.String' to type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2010-07-04" from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException]
Field error in object 'javaBean' on field 'dates[1]': rejected value [2011-07-04]; codes [typeMismatch.javaBean.dates[1],typeMismatch.javaBean.dates,typeMismatch.dates[1],typeMismatch.dates,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [javaBean.dates[1],dates[1]]; arguments []; default message [dates[1]]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dates[1]'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2011-07-04" from type 'java.lang.String' to type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2011-07-04" from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException]
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:809)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:358)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:170)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
... deploying the app, and clicking on the "JavaBean with String-to-propertyType conversion" link in the "Type Conversion" section of the home page.
I tested against 3.0.4 snapshot, 3.0.3, 3.0.2, and 3.0.1, and apparently this never worked. Interestingly, binding a String request parameter to a annotated @Controller List<Date> method argument works fine.
Debugging indicates that the BeanWrapper is losing (or never capturing) the annotation metadata when it passes a target TypeDescriptor to the ConversionService to perform the element conversion. This loss of information appears to begin on line 974 of BeanWrapperImpl in the call to convertIfNecessary.
Not sure the extent of the #11170 fix, but it appears this functionality hasn't yet been incorporated into BeanWrapper.
This did work for converting a full list/map but not for individual list/map elements. As of tonight's 3.0.4 snapshot, it should work for individual elements as well now.
Keith Donald opened SPR-7348 and commented
To reproduce:
@DateTimeFormat
(iso=Iso.DATE) List<Date> dates;This can be conveniently reproduced by checking out:
https://src.springsource.org/svn/spring-samples/mvc-showcase/
... deploying the app, and clicking on the "JavaBean with String-to-propertyType conversion" link in the "Type Conversion" section of the home page.
I tested against 3.0.4 snapshot, 3.0.3, 3.0.2, and 3.0.1, and apparently this never worked. Interestingly, binding a String request parameter to a annotated
@Controller
List<Date> method argument works fine.Affects: 3.0.3
Issue Links:
Referenced from: commits 66abad2
The text was updated successfully, but these errors were encountered: