Skip to content

Commit

Permalink
1.0.10: fix error for inside enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtu222 committed Feb 11, 2019
1 parent 88b7951 commit bfc15c2
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This BeanUtils library is a Java bean copy utility with powerful functionality a
<dependency>
<groupId>com.github.yangtu222</groupId>
<artifactId>BeanUtils</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
~~~

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.github.yangtu222</groupId>
<artifactId>BeanUtils</artifactId>
<name>BeanUtils</name>
<version>1.0.9</version>
<version>1.0.10</version>
<description>BeanUtils library is a Java bean copy utility with powerful functionality and high performance.</description>
<url>https://github.com/yangtu222/BeanUtils</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public static List<BeanCopyPropertyItem> 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;
}
}
}

Expand Down Expand Up @@ -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;
Expand Down
97 changes: 97 additions & 0 deletions src/test/java/com/tuyang/test/testEnum2/FromBean.java
Original file line number Diff line number Diff line change
@@ -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<MyEnum> myEnums3;

private List<String> 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<MyEnum> getMyEnums3() {
return myEnums3;
}

public void setMyEnums3(List<MyEnum> myEnums3) {
this.myEnums3 = myEnums3;
}

public List<String> geteStrings() {
return eStrings;
}

public void seteStrings(List<String> eStrings) {
this.eStrings = eStrings;
}



}
21 changes: 21 additions & 0 deletions src/test/java/com/tuyang/test/testEnum2/Inside.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
7 changes: 7 additions & 0 deletions src/test/java/com/tuyang/test/testEnum2/MyEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tuyang.test.testEnum2;

public enum MyEnum {
One,
Two,
Three
}
48 changes: 48 additions & 0 deletions src/test/java/com/tuyang/test/testEnum2/Test08.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

20 changes: 20 additions & 0 deletions src/test/java/com/tuyang/test/testEnum2/ToBean.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit bfc15c2

Please sign in to comment.