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
{{ message }}
Repository navigation
Validation failure not exposed next to binding failure for immutable form class [SPR-16841] #21381
While I was able to reproduce the other two data class issues, this one seems to work for me: I always get constraint violations for all affected fields reported. Could you double-check what was going wrong for you here?
I see what you mean now: With immutable form classes, we aggregate type mismatches in the initial pass when trying to construct the instance, so type mismatches will appear on their own first. We can't run the regular bean validation step in such a case since there is literally no instance state to introspect yet and therefore no other field values to validate; that's unfortunately a limitation in the common JSR-303 instance model. For that reason, regular constraint violations will only appear once all type mismatches have been resolved and an instance could be constructed.
In case of type mismatches, we could individually validate other property values through Validator.validateValue (getting a constraint 'preview' report for the case when we would bind a specific value, instead of a post-binding report against a full object instance) and aggregate them in the same phase. This would roughly lead to the same validation report as in the instance case. I'll give that a try.
This works for me in a unit test (ServletAnnotationControllerHandlerMethodTests.dataClassBindingWithValidationErrorAndConversionError)... Could you try to isolate your case a bit further so that we can identify the differences?
I'll keep this ticket marked as resolved for RC1, with the intended feature at least partially working there. For follow-up work based on your scenario, please create a separate ticket which I'll look at ASAP.
Activity
spring-projects-issues commentedon Jul 16, 2018
Juergen Hoeller commented
While I was able to reproduce the other two data class issues, this one seems to work for me: I always get constraint violations for all affected fields reported. Could you double-check what was going wrong for you here?
spring-projects-issues commentedon Jul 17, 2018
Masatoshi Tada commented
Thank you for your check!
I've checked again just now, and I found my mistakes.
But validation behaviors of two are still different. (See attached images)
When form is immutable and type conversion failed at "Birthday", there is no messages at "Message".
Could you take a look again?
!immutable-20180717.png!
!mutable-20180717.png!
spring-projects-issues commentedon Jul 17, 2018
Juergen Hoeller commented
I see what you mean now: With immutable form classes, we aggregate type mismatches in the initial pass when trying to construct the instance, so type mismatches will appear on their own first. We can't run the regular bean validation step in such a case since there is literally no instance state to introspect yet and therefore no other field values to validate; that's unfortunately a limitation in the common JSR-303 instance model. For that reason, regular constraint violations will only appear once all type mismatches have been resolved and an instance could be constructed.
In case of type mismatches, we could individually validate other property values through
Validator.validateValue(getting a constraint 'preview' report for the case when we would bind a specific value, instead of a post-binding report against a full object instance) and aggregate them in the same phase. This would roughly lead to the same validation report as in the instance case. I'll give that a try.spring-projects-issues commentedon Jul 17, 2018
Juergen Hoeller commented
This will be available in the upcoming
5.1.0.BUILD-SNAPSHOT. Please give it an early try...spring-projects-issues commentedon Aug 8, 2018
Masatoshi Tada commented
Thank you so much!
I tried Spring 5.1.RC1, and unfortunately it seemed that this issue is not fixed.
Could you check it again, please?
spring-projects-issues commentedon Aug 9, 2018
Juergen Hoeller commented
This works for me in a unit test (
ServletAnnotationControllerHandlerMethodTests.dataClassBindingWithValidationErrorAndConversionError)... Could you try to isolate your case a bit further so that we can identify the differences?spring-projects-issues commentedon Aug 14, 2018
Juergen Hoeller commented
I'll keep this ticket marked as resolved for RC1, with the intended feature at least partially working there. For follow-up work based on your scenario, please create a separate ticket which I'll look at ASAP.