Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanWrapper Binding with ConversionService: Annotation-driven type conversion rules not applied to List elements [SPR-7348] #12007

Closed
spring-projects-issues opened this issue Jul 3, 2010 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 3, 2010

Keith Donald opened SPR-7348 and commented

To reproduce:

  • 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)

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 3, 2010

Keith Donald commented

#11170 shows this issue to be resolved, but that's not what my tests show.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 3, 2010

Keith Donald commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants