This is an automated email from the ASF dual-hosted git repository.

pandalee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new d3691fcd feat(java): support nested bean in array/collection/map for 
row format (#2116)
d3691fcd is described below

commit d3691fcde21e412642062c2c3895899273d5aa51
Author: Shawn Yang <[email protected]>
AuthorDate: Sun Mar 23 19:59:29 2025 +0800

    feat(java): support nested bean in array/collection/map for row format 
(#2116)
    
    ## What does this PR do?
    
    support nested bean in array/collection/map for row format
    
    ## Related issues
    
    Closes #2106
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fury/issues/new/choose) describing the
    need to do so and update the document if necessary.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
---
 .../main/java/org/apache/fury/type/TypeUtils.java  | 46 +++++++++++++++-------
 .../java/org/apache/fury/type/TypeUtilsTest.java   | 21 ++++++++++
 2 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java 
b/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java
index e0acf5f7..bb9f4ae2 100644
--- a/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java
+++ b/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java
@@ -686,21 +686,37 @@ public class TypeUtils {
       typeRefs.addAll(getAllTypeArguments(typeRef));
     }
 
-    typeRefs.stream()
-        .filter(typeToken -> isBean(getRawType(typeToken)))
-        .forEach(
-            typeToken -> {
-              Class<?> cls = getRawType(typeToken);
-              beans.add(cls);
-              if (walkedTypePath.contains(typeToken)) {
-                throw new UnsupportedOperationException(
-                    "cyclic type is not supported. walkedTypePath: " + 
walkedTypePath);
-              } else {
-                LinkedHashSet<TypeRef<?>> newPath = new 
LinkedHashSet<>(walkedTypePath);
-                newPath.add(typeToken);
-                beans.addAll(listBeansRecursiveInclusive(cls, newPath));
-              }
-            });
+    for (TypeRef<?> typeToken : typeRefs) {
+      Class<?> type = getRawType(typeToken);
+      if (isBean(type)) {
+        beans.add(type);
+        if (walkedTypePath.contains(typeToken)) {
+          throw new UnsupportedOperationException(
+              "cyclic type is not supported. walkedTypePath: " + 
walkedTypePath);
+        } else {
+          LinkedHashSet<TypeRef<?>> newPath = new 
LinkedHashSet<>(walkedTypePath);
+          newPath.add(typeToken);
+          beans.addAll(listBeansRecursiveInclusive(type, newPath));
+        }
+      } else if (isCollection(type)) {
+        TypeRef<?> elementType = getElementType(typeToken);
+        LinkedHashSet<TypeRef<?>> newPath = new 
LinkedHashSet<>(walkedTypePath);
+        newPath.add(elementType);
+        beans.addAll(listBeansRecursiveInclusive(elementType.getClass(), 
newPath));
+      } else if (isMap(type)) {
+        Tuple2<TypeRef<?>, TypeRef<?>> mapKeyValueType = 
getMapKeyValueType(typeToken);
+        LinkedHashSet<TypeRef<?>> newPath = new 
LinkedHashSet<>(walkedTypePath);
+        newPath.add(mapKeyValueType.f0);
+        newPath.add(mapKeyValueType.f1);
+        
beans.addAll(listBeansRecursiveInclusive(mapKeyValueType.f0.getRawType(), 
newPath));
+        
beans.addAll(listBeansRecursiveInclusive(mapKeyValueType.f1.getRawType(), 
newPath));
+      } else if (type.isArray()) {
+        Class<?> arrayComponent = getArrayComponent(type);
+        LinkedHashSet<TypeRef<?>> newPath = new 
LinkedHashSet<>(walkedTypePath);
+        newPath.add(TypeRef.of(arrayComponent));
+        beans.addAll(listBeansRecursiveInclusive(arrayComponent, newPath));
+      }
+    }
     return beans;
   }
 
diff --git 
a/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java 
b/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java
index 0dbd5851..848f8f3d 100644
--- a/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java
+++ b/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java
@@ -132,6 +132,27 @@ public class TypeUtilsTest {
     assertEquals(classes.size(), 2);
   }
 
+  public static class ListBeanGenericFoo1 {}
+
+  public static class ListBeanGenericFoo2 {}
+
+  public static class ListBeanGenericFoo3 {}
+
+  public static class ListBeanGenericFoo4 {}
+
+  public static class ListBeanGeneric {
+    List<ListBeanGenericFoo1> f1;
+    ListBeanGenericFoo2[] f2;
+    Map<ListBeanGenericFoo3, ListBeanGenericFoo4> f3;
+  }
+
+  @Test
+  public void listBeanGeneric() {
+    LinkedHashSet<Class<?>> classes = 
TypeUtils.listBeansRecursiveInclusive(ListBeanGeneric.class);
+    // System.out.println(classes);
+    assertEquals(classes.size(), 5);
+  }
+
   @Test
   public void isBean() {
     Assert.assertTrue(TypeUtils.isBean(BeanA.class));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to