-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Honor generic type information in BeanUtils.copyProperties() #24281
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
Conversation
…operties with BeanUtils
SPR-24187 Enhanced datatype conversion possibilities while copying properties with BeanUtils
SPR-24187 Enhanced datatype conversion possibilities while copying properties with BeanUtils
Thanks for the PR. In #24187, my understanding is that we would want to honor generics when matching properties to copy. In other words, I don't think we actually want to convert properties, since that might lead to unexpected results -- for example, loss of information when converting from As a side note...
|
Thanks for your feedback. And for conversion from Without any conversion how can we achieve this? or else you mean to say allow to copy only if both (source & target) property's datatypes are matching otherwise skip (no |
Yes, I was saying that I think we would only want to copy properties if they are compatible without conversion. @jhoeller, what are your thoughts on the matter? |
I have pushed new implementation to copy properties without conversion. And it copies only if source and target property's types are matching. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the modifying the original PR.
I have reviewed the changes and added comments.
Please note, however, that I do not expect you to implement the changes, since I have already done so here (https://github.com/sbrannen/spring-framework/commits/issues/gh-24187-bean-utils-copy-properties-with-generic-types).
It turned out easier for me that way.
Once we branch for 5.3, I will merge my feature branch and keep your commit to give you credit for the work you've done to get the ball rolling with this feature enhancement.
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
Outdated
Show resolved
Hide resolved
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
Outdated
Show resolved
Hide resolved
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
Outdated
Show resolved
Hide resolved
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
Outdated
Show resolved
Hide resolved
spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java
Outdated
Show resolved
Hide resolved
@sbrannen You have already done changes in https://github.com/sbrannen/spring-framework/commits/issues/gh-24187-bean-utils-copy-properties-with-generic-types, I am resolving review comments. Thanks |
Prior to this commit, BeanUtils.copyProperties() ignored generic type information when comparing candidate source and target property types. This commit reworks the implementation of BeanUtils.copyProperties() so that generic type information is taken into account when copying properties. See gh-24281
Prior to this commit, BeanUtils.copyProperties() ignored generic type information when comparing candidate source and target property types. This commit reworks the implementation of BeanUtils.copyProperties() so that generic type information is taken into account when copying properties. See spring-projectsgh-24281
gh-24281 introduced support to honor generic type information in BeanUtils.copyProperties(), but that introduced a regression. Specifically, if the supplied source or target object lacked generic type information for the return type of the read-method or the parameter type of the write-method for a given property, respectively, the two properties would be considered a mismatch and ignored. This can occur if the source or target object is a java.lang.reflect.Proxy since the dynamically generated class for the proxy loses the generic type information from interfaces that the proxy implements. This commit fixes this regression by ignoring generic type information if either the source or target property is lacking generic type information. Closes gh-26531
spring-projectsgh-24281 introduced support to honor generic type information in BeanUtils.copyProperties(), but that introduced a regression. Specifically, if the supplied source or target object lacked generic type information for the return type of the read-method or the parameter type of the write-method for a given property, respectively, the two properties would be considered a mismatch and ignored. This can occur if the source or target object is a java.lang.reflect.Proxy since the dynamically generated class for the proxy loses the generic type information from interfaces that the proxy implements. This commit fixes this regression by ignoring generic type information if either the source or target property is lacking generic type information. Closes spring-projectsgh-26531
Fixes #24187 Honor generic type information when copying properties with BeanUtils
Handled standard supported Type Casting of properties. Any custom Object level property casting is restricted.