diff --git a/hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java b/hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java index fdb5fec9f..2b969f60a 100644 --- a/hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java +++ b/hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java @@ -402,9 +402,11 @@ public BiFunction, Class, String> createGetterFunction() { Field field = ReflectionUtils.findField(targetBeanType, name); boolean hasGeneric = false; if (field != null) { - String[] arr = Arrays.stream(ResolvableType.forField(field) - .getGenerics()) - .map(ResolvableType::getRawClass) + ResolvableType fieldType = ResolvableType.forField( + field, + ResolvableType.forClass(targetBeanType).as(field.getDeclaringClass())); + String[] arr = Arrays.stream(fieldType.getGenerics()) + .map(ResolvableType::resolve) .filter(Objects::nonNull) .map(t -> t.getName().concat(".class")) .toArray(String[]::new); diff --git a/hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierBeanTest.java b/hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierBeanTest.java new file mode 100644 index 000000000..1df2aa84a --- /dev/null +++ b/hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierBeanTest.java @@ -0,0 +1,63 @@ +package org.hswebframework.web.bean; + +import lombok.Getter; +import lombok.Setter; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +public class FastBeanCopierBeanTest { + + @Test + public void testCopyDirectGenericListField() { + Map source = Map.of( + "fileData", + List.of(Map.of("name", "image.jpg")) + ); + + DirectOutput output = FastBeanCopier.copy(source, new DirectOutput()); + + Assert.assertNotNull(output.getFileData()); + Assert.assertEquals(1, output.getFileData().size()); + Assert.assertTrue(output.getFileData().get(0) instanceof FileItem); + Assert.assertEquals("image.jpg", output.getFileData().get(0).getName()); + } + + @Test + public void testCopyGenericSuperclassListField() { + Map source = Map.of( + "fileData", + List.of(Map.of("name", "image.jpg")) + ); + + GenericOutput output = FastBeanCopier.copy(source, new GenericOutput()); + + Assert.assertNotNull(output.getFileData()); + Assert.assertEquals(1, output.getFileData().size()); + Assert.assertTrue(output.getFileData().get(0) instanceof FileItem); + Assert.assertEquals("image.jpg", output.getFileData().get(0).getName()); + } + + @Getter + @Setter + public static class DirectOutput { + private List fileData; + } + + @Getter + @Setter + public static class GenericBase { + private List fileData; + } + + public static class GenericOutput extends GenericBase { + } + + @Getter + @Setter + public static class FileItem { + private String name; + } +}