如何使用 BeanUtils copyProperties 从布尔值复制到布尔值?
开箱即用的 BeanUtils copyProperties 似乎无法处理从布尔对象属性到布尔原始属性的复制。
我想我可以创建并注册一个转换器来处理这个问题,但这似乎不起作用。
那么,如何使用 BeanUtils 将属性从类 Source 复制到类 Destination,其中:
public class Destination {
private boolean property;
public boolean isProperty() {
return property;
}
public void setProperty(boolean property) {
this.property = property;
}
}
public class Source{
private Boolean property;
public Boolean getProperty() {
return property;
}
public void setProperty(Boolean property) {
this.property = property;
}
}
BeanUtils copyProperties, out of the box, doesn't seem to handle copying from Boolean object properties to boolean primitive properties.
I figured I could create and register a converter to handle this, but that just didn't seem to work.
So, how can I use BeanUtils to copy the properties from class Source to class Destination where:
public class Destination {
private boolean property;
public boolean isProperty() {
return property;
}
public void setProperty(boolean property) {
this.property = property;
}
}
public class Source{
private Boolean property;
public Boolean getProperty() {
return property;
}
public void setProperty(Boolean property) {
this.property = property;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上反之亦然:
It is actually vice-versa: