Skip to content

Commit bfc15c2

Browse files
committed
1.0.10: fix error for inside enum.
1 parent 88b7951 commit bfc15c2

File tree

8 files changed

+201
-3
lines changed

8 files changed

+201
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This BeanUtils library is a Java bean copy utility with powerful functionality a
88
<dependency>
99
<groupId>com.github.yangtu222</groupId>
1010
<artifactId>BeanUtils</artifactId>
11-
<version>1.0.9</version>
11+
<version>1.0.10</version>
1212
</dependency>
1313
~~~
1414

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.github.yangtu222</groupId>
66
<artifactId>BeanUtils</artifactId>
77
<name>BeanUtils</name>
8-
<version>1.0.9</version>
8+
<version>1.0.10</version>
99
<description>BeanUtils library is a Java bean copy utility with powerful functionality and high performance.</description>
1010
<url>https://github.com/yangtu222/BeanUtils</url>
1111

src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyCache.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public static List<BeanCopyPropertyItem> buildBeanCopyPropertyItem(Class<?> sour
178178
Class<?> sourceClassFromAnnotation = beanCopySource.source();
179179
if( sourceClassFromAnnotation.isAssignableFrom(sourceClass) ) {
180180
beanAnnotationSource = sourceClassFromAnnotation;
181+
} else {
182+
//fix sourceClass is proxy class.
183+
if( sourceClass.getName().startsWith(sourceClassFromAnnotation.getName()) ) {
184+
beanAnnotationSource = sourceClassFromAnnotation;
185+
}
181186
}
182187
}
183188

@@ -389,7 +394,7 @@ else if( !targetIsArray ) {
389394

390395
if( PropertyUtils.isAssignable(methodTargetType, methodSourceType) ) {
391396

392-
if( PropertyUtils.isPrimitive(methodTargetType)) {
397+
if( PropertyUtils.isPrimitive(methodTargetType) || methodTargetType.isEnum() ) {
393398
BeanCopyPropertyItem item = new BeanCopyPropertyItem();
394399

395400
item.propertyName = propertyName;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.tuyang.test.testEnum2;
2+
3+
import java.util.List;
4+
5+
public class FromBean {
6+
7+
private MyEnum myEnum1;
8+
private MyEnum myEnum2;
9+
10+
private String enumString;
11+
12+
private MyEnum[] myEnums1;
13+
private MyEnum[] myEnums2;
14+
15+
private String[] enumStrings;
16+
17+
private List<MyEnum> myEnums3;
18+
19+
private List<String> eStrings;
20+
21+
private Inside inside;
22+
23+
public Inside getInside() {
24+
return inside;
25+
}
26+
27+
public void setInside(Inside inside) {
28+
this.inside = inside;
29+
}
30+
31+
public MyEnum getMyEnum1() {
32+
return myEnum1;
33+
}
34+
35+
public void setMyEnum1(MyEnum myEnum1) {
36+
this.myEnum1 = myEnum1;
37+
}
38+
39+
public MyEnum getMyEnum2() {
40+
return myEnum2;
41+
}
42+
43+
public void setMyEnum2(MyEnum myEnum2) {
44+
this.myEnum2 = myEnum2;
45+
}
46+
47+
public String getEnumString() {
48+
return enumString;
49+
}
50+
51+
public void setEnumString(String enumString) {
52+
this.enumString = enumString;
53+
}
54+
55+
public MyEnum[] getMyEnums1() {
56+
return myEnums1;
57+
}
58+
59+
public void setMyEnums1(MyEnum[] myEnums1) {
60+
this.myEnums1 = myEnums1;
61+
}
62+
63+
public MyEnum[] getMyEnums2() {
64+
return myEnums2;
65+
}
66+
67+
public void setMyEnums2(MyEnum[] myEnums2) {
68+
this.myEnums2 = myEnums2;
69+
}
70+
71+
public String[] getEnumStrings() {
72+
return enumStrings;
73+
}
74+
75+
public void setEnumStrings(String[] enumStrings) {
76+
this.enumStrings = enumStrings;
77+
}
78+
79+
public List<MyEnum> getMyEnums3() {
80+
return myEnums3;
81+
}
82+
83+
public void setMyEnums3(List<MyEnum> myEnums3) {
84+
this.myEnums3 = myEnums3;
85+
}
86+
87+
public List<String> geteStrings() {
88+
return eStrings;
89+
}
90+
91+
public void seteStrings(List<String> eStrings) {
92+
this.eStrings = eStrings;
93+
}
94+
95+
96+
97+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.tuyang.test.testEnum2;
2+
3+
public class Inside {
4+
5+
private String a;
6+
private MyEnum b;
7+
8+
public String getA() {
9+
return a;
10+
}
11+
public void setA(String a) {
12+
this.a = a;
13+
}
14+
public MyEnum getB() {
15+
return b;
16+
}
17+
public void setB(MyEnum b) {
18+
this.b = b;
19+
}
20+
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tuyang.test.testEnum2;
2+
3+
public enum MyEnum {
4+
One,
5+
Two,
6+
Three
7+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.tuyang.test.testEnum2;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.lang.reflect.Array;
6+
import java.util.Arrays;
7+
8+
import org.junit.Test;
9+
10+
import com.tuyang.beanutils.BeanCopyUtils;
11+
12+
public class Test08 {
13+
14+
private FromBean getFromBean() {
15+
FromBean fromBean = new FromBean();
16+
17+
fromBean.setMyEnum1(MyEnum.One);
18+
fromBean.setMyEnum2(MyEnum.Two);
19+
fromBean.setEnumString(MyEnum.Three.toString());
20+
21+
MyEnum[] array = new MyEnum[2];
22+
array[0]= MyEnum.One;
23+
array[1] = MyEnum.Three;
24+
fromBean.setMyEnums1(array);
25+
fromBean.setMyEnums2(array);
26+
fromBean.setMyEnums3(Arrays.asList(array));
27+
28+
String[] enumStrings = new String[2];
29+
enumStrings[0] = MyEnum.Three.toString();
30+
enumStrings[1] = MyEnum.Two.toString();
31+
32+
fromBean.setEnumStrings(enumStrings);
33+
fromBean.seteStrings(Arrays.asList(enumStrings));
34+
fromBean.setInside(new Inside());
35+
fromBean.getInside().setB(MyEnum.One);
36+
37+
return fromBean;
38+
}
39+
40+
@Test
41+
public void testEnum() {
42+
FromBean fromBean = getFromBean();
43+
ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class);
44+
45+
assertEquals(toBean.getMyEnum(), MyEnum.One);
46+
}
47+
}
48+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.tuyang.test.testEnum2;
2+
3+
import com.tuyang.beanutils.annotation.BeanCopySource;
4+
import com.tuyang.beanutils.annotation.CopyProperty;
5+
6+
@BeanCopySource(source=FromBean.class)
7+
public class ToBean {
8+
9+
@CopyProperty(property = "inside.b")
10+
private MyEnum myEnum;
11+
12+
public MyEnum getMyEnum() {
13+
return myEnum;
14+
}
15+
16+
public void setMyEnum(MyEnum myEnum) {
17+
this.myEnum = myEnum;
18+
}
19+
20+
}

0 commit comments

Comments
 (0)