diff --git a/README.md b/README.md index d1f7015..eec949c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This BeanUtils library is a Java bean copy utility with powerful functionality a com.github.yangtu222 BeanUtils - 1.0.9 + 1.0.10 ~~~ diff --git a/pom.xml b/pom.xml index 9984788..59b3d42 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.yangtu222 BeanUtils BeanUtils - 1.0.9 + 1.0.10 BeanUtils library is a Java bean copy utility with powerful functionality and high performance. https://github.com/yangtu222/BeanUtils diff --git a/src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyCache.java b/src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyCache.java index 52471c2..25715f7 100644 --- a/src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyCache.java +++ b/src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyCache.java @@ -178,6 +178,11 @@ public static List buildBeanCopyPropertyItem(Class sour Class sourceClassFromAnnotation = beanCopySource.source(); if( sourceClassFromAnnotation.isAssignableFrom(sourceClass) ) { beanAnnotationSource = sourceClassFromAnnotation; + } else { + //fix sourceClass is proxy class. + if( sourceClass.getName().startsWith(sourceClassFromAnnotation.getName()) ) { + beanAnnotationSource = sourceClassFromAnnotation; + } } } @@ -389,7 +394,7 @@ else if( !targetIsArray ) { if( PropertyUtils.isAssignable(methodTargetType, methodSourceType) ) { - if( PropertyUtils.isPrimitive(methodTargetType)) { + if( PropertyUtils.isPrimitive(methodTargetType) || methodTargetType.isEnum() ) { BeanCopyPropertyItem item = new BeanCopyPropertyItem(); item.propertyName = propertyName; diff --git a/src/test/java/com/tuyang/test/testEnum2/FromBean.java b/src/test/java/com/tuyang/test/testEnum2/FromBean.java new file mode 100644 index 0000000..69c53b9 --- /dev/null +++ b/src/test/java/com/tuyang/test/testEnum2/FromBean.java @@ -0,0 +1,97 @@ +package com.tuyang.test.testEnum2; + +import java.util.List; + +public class FromBean { + + private MyEnum myEnum1; + private MyEnum myEnum2; + + private String enumString; + + private MyEnum[] myEnums1; + private MyEnum[] myEnums2; + + private String[] enumStrings; + + private List myEnums3; + + private List eStrings; + + private Inside inside; + + public Inside getInside() { + return inside; + } + + public void setInside(Inside inside) { + this.inside = inside; + } + + public MyEnum getMyEnum1() { + return myEnum1; + } + + public void setMyEnum1(MyEnum myEnum1) { + this.myEnum1 = myEnum1; + } + + public MyEnum getMyEnum2() { + return myEnum2; + } + + public void setMyEnum2(MyEnum myEnum2) { + this.myEnum2 = myEnum2; + } + + public String getEnumString() { + return enumString; + } + + public void setEnumString(String enumString) { + this.enumString = enumString; + } + + public MyEnum[] getMyEnums1() { + return myEnums1; + } + + public void setMyEnums1(MyEnum[] myEnums1) { + this.myEnums1 = myEnums1; + } + + public MyEnum[] getMyEnums2() { + return myEnums2; + } + + public void setMyEnums2(MyEnum[] myEnums2) { + this.myEnums2 = myEnums2; + } + + public String[] getEnumStrings() { + return enumStrings; + } + + public void setEnumStrings(String[] enumStrings) { + this.enumStrings = enumStrings; + } + + public List getMyEnums3() { + return myEnums3; + } + + public void setMyEnums3(List myEnums3) { + this.myEnums3 = myEnums3; + } + + public List geteStrings() { + return eStrings; + } + + public void seteStrings(List eStrings) { + this.eStrings = eStrings; + } + + + +} diff --git a/src/test/java/com/tuyang/test/testEnum2/Inside.java b/src/test/java/com/tuyang/test/testEnum2/Inside.java new file mode 100644 index 0000000..5b5c194 --- /dev/null +++ b/src/test/java/com/tuyang/test/testEnum2/Inside.java @@ -0,0 +1,21 @@ +package com.tuyang.test.testEnum2; + +public class Inside { + + private String a; + private MyEnum b; + + public String getA() { + return a; + } + public void setA(String a) { + this.a = a; + } + public MyEnum getB() { + return b; + } + public void setB(MyEnum b) { + this.b = b; + } + +} diff --git a/src/test/java/com/tuyang/test/testEnum2/MyEnum.java b/src/test/java/com/tuyang/test/testEnum2/MyEnum.java new file mode 100644 index 0000000..e530766 --- /dev/null +++ b/src/test/java/com/tuyang/test/testEnum2/MyEnum.java @@ -0,0 +1,7 @@ +package com.tuyang.test.testEnum2; + +public enum MyEnum { + One, + Two, + Three +} diff --git a/src/test/java/com/tuyang/test/testEnum2/Test08.java b/src/test/java/com/tuyang/test/testEnum2/Test08.java new file mode 100644 index 0000000..edd0e1f --- /dev/null +++ b/src/test/java/com/tuyang/test/testEnum2/Test08.java @@ -0,0 +1,48 @@ +package com.tuyang.test.testEnum2; + +import static org.junit.Assert.*; + +import java.lang.reflect.Array; +import java.util.Arrays; + +import org.junit.Test; + +import com.tuyang.beanutils.BeanCopyUtils; + +public class Test08 { + + private FromBean getFromBean() { + FromBean fromBean = new FromBean(); + + fromBean.setMyEnum1(MyEnum.One); + fromBean.setMyEnum2(MyEnum.Two); + fromBean.setEnumString(MyEnum.Three.toString()); + + MyEnum[] array = new MyEnum[2]; + array[0]= MyEnum.One; + array[1] = MyEnum.Three; + fromBean.setMyEnums1(array); + fromBean.setMyEnums2(array); + fromBean.setMyEnums3(Arrays.asList(array)); + + String[] enumStrings = new String[2]; + enumStrings[0] = MyEnum.Three.toString(); + enumStrings[1] = MyEnum.Two.toString(); + + fromBean.setEnumStrings(enumStrings); + fromBean.seteStrings(Arrays.asList(enumStrings)); + fromBean.setInside(new Inside()); + fromBean.getInside().setB(MyEnum.One); + + return fromBean; + } + + @Test + public void testEnum() { + FromBean fromBean = getFromBean(); + ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); + + assertEquals(toBean.getMyEnum(), MyEnum.One); + } +} + diff --git a/src/test/java/com/tuyang/test/testEnum2/ToBean.java b/src/test/java/com/tuyang/test/testEnum2/ToBean.java new file mode 100644 index 0000000..f154280 --- /dev/null +++ b/src/test/java/com/tuyang/test/testEnum2/ToBean.java @@ -0,0 +1,20 @@ +package com.tuyang.test.testEnum2; + +import com.tuyang.beanutils.annotation.BeanCopySource; +import com.tuyang.beanutils.annotation.CopyProperty; + +@BeanCopySource(source=FromBean.class) +public class ToBean { + + @CopyProperty(property = "inside.b") + private MyEnum myEnum; + + public MyEnum getMyEnum() { + return myEnum; + } + + public void setMyEnum(MyEnum myEnum) { + this.myEnum = myEnum; + } + +} \ No newline at end of file