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.

Comment From: sbrannen

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 Float to Integer in the tests in this PR.

As a side note...

Note: Due to its reliance on PropertyEditors, SimpleTypeConverter is not thread-safe. Use a separate instance for each thread.

Comment From: kpkunal1406

@sbrannen ,

Thanks for your feedback. If we do not convert properties then target property's datatype will remain as source (As per current implementation no need to change anything). for e.g. List<Integer> is copied into List<String>. Here generic datatype is List. But when we actually fetch it target property it will be List<Integer>.

And for conversion from Float to Integer in test case is as sample example. User must be knowing while copying properties from source to target (what he/she is doing). This can be taken care by the developer.

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 (nojava.lang.ClassCastException)?

Comment From: sbrannen

or else you mean to say allow to copy only if both (source & target) property's datatypes are matching otherwise skip (nojava.lang.ClassCastException)?

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?

Comment From: kpkunal1406

@sbrannen ,

I have pushed new implementation to copy properties without conversion. And it copies only if source and target property's types are matching.

Comment From: kpkunal1406

@sbrannen I appreciate your feedback and suggestions. It is very helpful.

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. However I have pushed changes into this request also.

Thanks

Comment From: sbrannen

This has been merged into master in 89ee0b077f7cc16441e056200257a54374dc2545 and revised in e74f868a2397def6b3f25c96fe08fcec36c36e26.