When Beanutils.copyproperties is used, the null value is also copied to make it a very chicken side.
He is extended to support a variety of null values are no longer copied
Public Abstract classBeanutilsextendsOrg.springframework.beans.BeanUtils { Public Static voidCopyproperties (object source, object target)throwsbeansexception {assert.notnull (source,"Source must not being null"); Assert.notnull (Target,"Target must not being null"); Class<?> actualeditable =Target.getclass (); Propertydescriptor[] Targetpds=getpropertydescriptors (actualeditable); for(PropertyDescriptor Targetpd:targetpds) {if(Targetpd.getwritemethod ()! =NULL) {PropertyDescriptor SOURCEPD=Getpropertydescriptor (Source.getclass (), Targetpd.getname ()); if(SOURCEPD! =NULL&& Sourcepd.getreadmethod ()! =NULL) { Try{Method Readmethod=Sourcepd.getreadmethod (); if(!Modifier.ispublic (Readmethod.getdeclaringclass (). getmodifiers ())) {readmethod.setaccessible (true); } Object Value=Readmethod.invoke (source); //This determines whether the following value is empty, of course, there are some special requirements such as binding format conversion and so on if(Value! =NULL) { BooleanIsEmpty =false; if(ValueinstanceofSet) {Set s=(Set) value; if(s = =NULL||S.isempty ()) {IsEmpty=true; } } Else if(ValueinstanceofMap) {Map m=(MAP) value; if(M = =NULL||M.isempty ()) {IsEmpty=true; } } Else if(ValueinstanceofList) {List L=(List) value; if(L = =NULL|| L.size () < 1) {IsEmpty=true; } } Else if(ValueinstanceofCollection) {Collection C=(Collection) value; if(c = =NULL|| C.size () < 1) {IsEmpty=true; } } if(!isEmpty) {Method Writemethod=Targetpd.getwritemethod (); if(!Modifier.ispublic (Writemethod.getdeclaringclass (). getmodifiers ())) {writemethod.setaccessible (true); } writemethod.invoke (target, value); } } } Catch(Throwable ex) {Throw NewFatalbeanexception ("Could not copy properties from source to target", ex); } } } } } }
Beanutils (Null empty collection empty list no longer replicated)