关于使用Spring的BeanUtils复制属性时Boolean类型无法复制的问题

阅读更多

spring-beans版本5.0.12

JDK版本1.8.0_181

 

使用BeanUtils.copyProperties(Object source, Object target)进行属性复制时,遇到了Boolean类型无法复制的问题,一步步的跟进了java的rt.jar包中的Instrospector类中,发现第513行只认boolean类型

if (argCount == 0) {
                        if (name.startsWith(GET_PREFIX)) {
                            // Simple getter
                            pd = new PropertyDescriptor(this.beanClass, name.substring(3), method, null);
                        } else if (resultType == boolean.class && name.startsWith(IS_PREFIX)) {
                            // Boolean getter
                            pd = new PropertyDescriptor(this.beanClass, name.substring(2), method, null);
                        }
                    }

 

所以,是不支持Boolean类型的复制,只支持boolean类型的复制

你可能感兴趣的:(关于使用Spring的BeanUtils复制属性时Boolean类型无法复制的问题)