diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ebd98e97..b498a0294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * 【core 】 修复CollUtil.subtract使用非标准Set等空指针问题(issue#I3XN1Z@Gitee) * 【core 】 修复SqlFormatter部分SQL空指针问题(issue#I3XS44@Gitee) * 【core 】 修复DateRange计算问题(issue#I3Y1US@Gitee) +* 【core 】 修复BeanCopier中setFieldNameEditor失效问题(pr#349@Gitee) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/bean/copier/BeanCopier.java b/hutool-core/src/main/java/cn/hutool/core/bean/copier/BeanCopier.java index 5e7a41a7f..bc11beefc 100644 --- a/hutool-core/src/main/java/cn/hutool/core/bean/copier/BeanCopier.java +++ b/hutool-core/src/main/java/cn/hutool/core/bean/copier/BeanCopier.java @@ -239,7 +239,7 @@ public class BeanCopier implements Copier, Serializable { // 对key做映射,映射后为null的忽略之 // 这里 copyOptions.editFieldName() 不能少,否则导致 CopyOptions setFieldNameEditor 失效 - String providerKey = copyOptions.editFieldName(copyOptions.getMappedFieldName(fieldName, false)); + final String providerKey = copyOptions.editFieldName(copyOptions.getMappedFieldName(fieldName, false)); if(null == providerKey){ return; } diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java index dffae51b6..9e3f54291 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java @@ -538,6 +538,14 @@ public class BeanUtilTest { Assert.assertEquals(new Long(123456L), station2.getId()); } + static class Station extends Tree {} + static class Tree extends Entity {} + + @Data + public static class Entity { + private T id; + } + @Test public void copyListTest() { Student student = new Student(); @@ -561,19 +569,6 @@ public class BeanUtilTest { } - public static class Station extends Tree { - - } - - public static class Tree extends Entity { - - } - - @Data - public static class Entity { - private T id; - } - @Test public void toMapTest() { // 测试转map的时候返回key @@ -650,8 +645,8 @@ public class BeanUtilTest { @Test public void beanToBeanCopyOptionsTest() { ChildVo1 childVo1 = new ChildVo1(); - childVo1.setChild_address("中国北京天安门"); - childVo1.setChild_name("张北京"); + childVo1.setChild_address("中国北京五道口"); + childVo1.setChild_name("张三"); childVo1.setChild_father_name("张无忌"); childVo1.setChild_mother_name("赵敏敏"); @@ -669,8 +664,7 @@ public class BeanUtilTest { Assert.assertEquals(childVo1.getChild_mother_name(), childVo2.getChildMotherName()); } - @Getter - @Setter + @Data public static class ChildVo1 { String child_name; String child_address; @@ -678,8 +672,7 @@ public class BeanUtilTest { String child_father_name; } - @Getter - @Setter + @Data public static class ChildVo2 { String childName; String childAddress;