The below code works in 5.2.9.RELEASE
BeanUtils.copyProperties(transferVO , transferRequest);
The classes where as follow. As you can see the source and destination beans has a List with same name but different types. But it was working
public class transferVO {
private List<Signer> signers;
}
public class transferRequest{
private List<TransferSigners > signers;
}
public class Signer{
private string name;
}
public class TransferSigners {
private string name;
}
After upgrade to 5.3.7
the signers
property is not copied.
Comment From: sbrannen
This is a potential regression introduced in conjunction with #24187.
@afattahi54, can you please also provide the setter and getter methods of those two classes so that we can inspect the actual method signatures?
Also, if Signer
is not a subtype of TransferSigners
, why would you expect BeanUtils
to copy from List<Signer>
to List<TransferSigners>
?
Doing so would actually store items in the List<TransferSigners>
that are not an instance of TransferSigners
, and that would be a broken state.
Comment From: afattahi54
The Signer
and TransferSigners
do not have same types. You are right, but as it was working before upgrade to 5.3.7
I expected it to keep working
The setters and getters are as below:
public class transferVO {
private List<Signer> signers;
public List<Signer> getSigners() {
return signers;
}
public void setSigners(List<Signer> signers) {
this.signers = signers;
}
}
public class transferRequest {
private List<TransferSigners > signers;
public List<TransferSigners> getSigners() {
return signers;
}
public void setSigners(List<TransferSigners> signers) {
this.signers = signers;
}
}
Thanks
Comment From: bigdata-page
This is a potential regression introduced in conjunction with #24187.
@afattahi54, can you please also provide the setter and getter methods of those two classes so that we can inspect the actual method signatures?
Also, if
Signer
is not a subtype ofTransferSigners
, why would you expectBeanUtils
to copy fromList<Signer>
toList<TransferSigners>
?Doing so would actually store items in the
List<TransferSigners>
that are not an instance ofTransferSigners
, and that would be a broken state.
@sbrannen spring-beans version is 5.3.9, when Signer is a subtype of TransferSigners,use the BeanUtils.copyProperties(transferVO , transferRequest). the transferVO.signers is null. but when spring-beans version is 5.1.16.RELEASE is normal. I hope the new version is compatible with the previous version.
Comment From: sbrannen
Assigned to the Triage Queue so that the team can determine if this is a regression that needs to be fixed.
Comment From: sbrannen
The
Signer
andTransferSigners
do not have same types. You are right, but as it was working before upgrade to5.3.7
I expected it to keep working
@afattahi54, since BeanUtils.copyProperties()
honors generics since Spring Framework 5.3, you will need to ensure that the source and target property types are compatible in terms of Java semantics.
spring-beans version is 5.3.9, when Signer is a subtype of TransferSigners,use the BeanUtils.copyProperties(transferVO , transferRequest). the transferVO.signers is null. but when spring-beans version is 5.1.16.RELEASE is normal. I hope the new version is compatible with the previous version.
@bigdata-page, that can be addressed by using an upper-bounded wildcard for the target property type.
In commit 887389d3413c4a1036095cff6f9cdebb34af87fe, I added a table to the Javadoc for BeanUtils.copyProperties()
which will hopefully help you and other users better understand the current semantics for property type matching.