From 74828a4afd15a47cd006216c13642ada9c11325d Mon Sep 17 00:00:00 2001 From: wcekan Date: Fri, 19 Feb 2021 19:04:22 -0500 Subject: [PATCH 1/6] Move Include to package-info --- .../example/packageshareable/ContainerWithPackageShare.java | 3 --- .../example/packageshareable/ShareableWithPackageShare.java | 3 --- .../example/packageshareable/UnshareableWithEntityUnshare.java | 2 -- .../src/test/java/example/packageshareable/package-info.java | 2 ++ .../main/java/com/yahoo/elide/models/generics/Employee.java | 3 --- .../src/main/java/com/yahoo/elide/models/generics/Manager.java | 3 --- .../java/com/yahoo/elide/models/generics/package-info.java | 2 ++ 7 files changed, 4 insertions(+), 14 deletions(-) diff --git a/elide-core/src/test/java/example/packageshareable/ContainerWithPackageShare.java b/elide-core/src/test/java/example/packageshareable/ContainerWithPackageShare.java index 5e4afa878e..ede3892ba9 100644 --- a/elide-core/src/test/java/example/packageshareable/ContainerWithPackageShare.java +++ b/elide-core/src/test/java/example/packageshareable/ContainerWithPackageShare.java @@ -5,8 +5,6 @@ */ package example.packageshareable; -import com.yahoo.elide.annotation.Include; - import java.util.Collection; import javax.persistence.Entity; @@ -20,7 +18,6 @@ * Container for ShareableWithPackageShare and UnshareableWithEntityUnshare. */ @Entity -@Include(rootLevel = true) public class ContainerWithPackageShare { private long id; private Collection unshareableWithEntityUnshares; diff --git a/elide-core/src/test/java/example/packageshareable/ShareableWithPackageShare.java b/elide-core/src/test/java/example/packageshareable/ShareableWithPackageShare.java index c2316a8f06..21ad5f5aa2 100644 --- a/elide-core/src/test/java/example/packageshareable/ShareableWithPackageShare.java +++ b/elide-core/src/test/java/example/packageshareable/ShareableWithPackageShare.java @@ -5,8 +5,6 @@ */ package example.packageshareable; -import com.yahoo.elide.annotation.Include; - import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -18,7 +16,6 @@ * Package level shareable bean. */ @Entity -@Include(rootLevel = true) public class ShareableWithPackageShare { private long id; private ContainerWithPackageShare container; diff --git a/elide-core/src/test/java/example/packageshareable/UnshareableWithEntityUnshare.java b/elide-core/src/test/java/example/packageshareable/UnshareableWithEntityUnshare.java index 41a6a3a88a..1c662c834f 100644 --- a/elide-core/src/test/java/example/packageshareable/UnshareableWithEntityUnshare.java +++ b/elide-core/src/test/java/example/packageshareable/UnshareableWithEntityUnshare.java @@ -5,7 +5,6 @@ */ package example.packageshareable; -import com.yahoo.elide.annotation.Include; import com.yahoo.elide.annotation.SharePermission; import javax.persistence.Entity; @@ -20,7 +19,6 @@ */ @Entity @SharePermission(sharable = false) -@Include(rootLevel = true) public class UnshareableWithEntityUnshare { private long id; private ContainerWithPackageShare container; diff --git a/elide-core/src/test/java/example/packageshareable/package-info.java b/elide-core/src/test/java/example/packageshareable/package-info.java index d7eb1cd923..01ee3a7db3 100644 --- a/elide-core/src/test/java/example/packageshareable/package-info.java +++ b/elide-core/src/test/java/example/packageshareable/package-info.java @@ -4,6 +4,8 @@ * See LICENSE file in project root for terms. */ @SharePermission +@Include(rootLevel = true) package example.packageshareable; +import com.yahoo.elide.annotation.Include; import com.yahoo.elide.annotation.SharePermission; diff --git a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Employee.java b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Employee.java index 6a3dc89cac..3a2c20bda2 100644 --- a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Employee.java +++ b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Employee.java @@ -6,14 +6,11 @@ package com.yahoo.elide.models.generics; -import com.yahoo.elide.annotation.Include; - import javax.persistence.Entity; /** * Helper class to test parameterized subclass/superclass hierarchies. */ -@Include(rootLevel = true) @Entity public class Employee extends Peon { } diff --git a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Manager.java b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Manager.java index 15ee741388..d0da067cfa 100644 --- a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Manager.java +++ b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Manager.java @@ -6,14 +6,11 @@ package com.yahoo.elide.models.generics; -import com.yahoo.elide.annotation.Include; - import javax.persistence.Entity; /** * Tests a parameterized superclass. */ -@Include(rootLevel = true) @Entity public class Manager extends Overlord { } diff --git a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/package-info.java b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/package-info.java index 515df0479b..55d0f0815a 100644 --- a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/package-info.java +++ b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/package-info.java @@ -4,7 +4,9 @@ * See LICENSE file in project root for terms. */ +@Include(rootLevel = true) @SharePermission package com.yahoo.elide.models.generics; +import com.yahoo.elide.annotation.Include; import com.yahoo.elide.annotation.SharePermission; From de539e33786150b7c39a45c64fd219334e8fca99 Mon Sep 17 00:00:00 2001 From: wcekan Date: Fri, 19 Feb 2021 21:25:03 -0500 Subject: [PATCH 2/6] Process Include in package-info --- .../datastore/inmemory/HashMapDataStore.java | 19 ++++++++++++++++++- .../InMemoryStoreTransactionTest.java | 10 ++++++++-- .../yahoo/elide/models/generics/Other.java | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 elide-example-models/src/main/java/com/yahoo/elide/models/generics/Other.java diff --git a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java index 5478ebdb93..a8e37d846e 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java @@ -5,6 +5,7 @@ */ package com.yahoo.elide.core.datastore.inmemory; +import com.yahoo.elide.annotation.Exclude; import com.yahoo.elide.annotation.Include; import com.yahoo.elide.core.DataStore; import com.yahoo.elide.core.DataStoreTransaction; @@ -15,6 +16,7 @@ import com.google.common.collect.Sets; import lombok.Getter; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -23,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import javax.persistence.Entity; + /** * Simple in-memory only database. */ @@ -42,7 +46,20 @@ public HashMapDataStore(Set beanPackages) { for (Package beanPackage : beanPackages) { ClassScanner.getAnnotatedClasses(beanPackage, Include.class).stream() .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) - .forEach(modelClass -> dataStore.put(modelClass, Collections.synchronizedMap(new LinkedHashMap<>()))); + .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, + Arrays.asList(Include.class, Exclude.class)) instanceof Include) + .forEach(modelClass -> dataStore.put(modelClass, + Collections.synchronizedMap(new LinkedHashMap<>()))); + } + + for (Package beanPackage : beanPackages) { + ClassScanner.getAnnotatedClasses(beanPackage, Entity.class).stream() + .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) + .filter(modelClass -> !dataStore.containsKey(modelClass)) + .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, + Arrays.asList(Include.class, Exclude.class)) instanceof Include) + .forEach(modelClass -> dataStore.put(modelClass, + Collections.synchronizedMap(new LinkedHashMap<>()))); } } diff --git a/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java b/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java index fdecf76b2e..534272b771 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java @@ -6,6 +6,7 @@ package com.yahoo.elide.core.datastore.inmemory; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -27,6 +28,7 @@ import com.yahoo.elide.core.filter.expression.FilterExpression; import com.yahoo.elide.core.pagination.Pagination; import com.yahoo.elide.core.sort.Sorting; +import com.yahoo.elide.models.generics.Manager; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -518,7 +520,8 @@ public void testSortingRequiresInMemoryPagination() { @Test public void testInMemoryDataStore() { - HashMapDataStore wrapped = new HashMapDataStore(Book.class.getPackage()); + HashMapDataStore wrapped = new HashMapDataStore(Sets.newHashSet( + Book.class.getPackage(), Manager.class.getPackage())); InMemoryDataStore store = new InMemoryDataStore(wrapped); DataStoreTransaction tx = store.beginReadTransaction(); assertEquals(InMemoryStoreTransaction.class, tx.getClass()); @@ -527,7 +530,6 @@ public void testInMemoryDataStore() { String tos = store.toString(); assertTrue(tos.contains("Data store contents")); - assertTrue(tos.contains("Table class example.NoReadEntity contents")); assertTrue(tos.contains("Table class example.Author contents")); assertTrue(tos.contains("Table class example.Book contents")); assertTrue(tos.contains("Table class example.Child contents")); @@ -542,6 +544,7 @@ public void testInMemoryDataStore() { assertTrue(tos.contains("Table class example.LineItem contents")); assertTrue(tos.contains("Table class example.MapColorShape contents")); assertTrue(tos.contains("Table class example.NoDeleteEntity contents")); + assertTrue(tos.contains("Table class example.NoReadEntity contents")); assertTrue(tos.contains("Table class example.NoShareEntity contents")); assertTrue(tos.contains("Table class example.NoUpdateEntity contents")); assertTrue(tos.contains("Table class example.Parent contents")); @@ -555,5 +558,8 @@ public void testInMemoryDataStore() { assertTrue(tos.contains("Table class example.packageshareable.ContainerWithPackageShare contents")); assertTrue(tos.contains("Table class example.packageshareable.ShareableWithPackageShare contents")); assertTrue(tos.contains("Table class example.packageshareable.UnshareableWithEntityUnshare contents")); + assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Employee contents")); + assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Manager contents")); + assertFalse(tos.contains("Table class com.yahoo.elide.models.generics.Other contents")); } } diff --git a/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Other.java b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Other.java new file mode 100644 index 0000000000..5988b3cf05 --- /dev/null +++ b/elide-example-models/src/main/java/com/yahoo/elide/models/generics/Other.java @@ -0,0 +1,19 @@ +/* + * Copyright 2021, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ + +package com.yahoo.elide.models.generics; + +import com.yahoo.elide.annotation.Exclude; + +import javax.persistence.Entity; + +/** + * Helper class to test parameterized subclass/superclass hierarchies. + */ +@Entity +@Exclude +public class Other extends Peon { +} From d56ad8b90d69cba881d5902004dfe72311acbcca Mon Sep 17 00:00:00 2001 From: wcekan Date: Thu, 11 Mar 2021 20:50:23 -0500 Subject: [PATCH 3/6] make one scan --- .../java/com/yahoo/elide/core/EntityBinding.java | 12 +++++++++++- .../core/datastore/inmemory/HashMapDataStore.java | 15 +-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java index ab35dac888..51de22288c 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java @@ -240,6 +240,16 @@ public List getAllFields() { */ private void bindEntityFields(Class cls, String type, Collection fieldOrMethodList) { for (AccessibleObject fieldOrMethod : fieldOrMethodList) { + // Special handling for Eclipse. Load missing annotations + if (fieldOrMethod.getAnnotations().length == 0 && fieldOrMethod instanceof Method) { + Method m = (Method) fieldOrMethod; + try { + fieldOrMethod = m.getDeclaringClass().getMethod(m.getName(), m.getParameterTypes()); + } catch (NoSuchMethodException | SecurityException e) { + // Not expected, leave alone + } + } + bindTriggerIfPresent(OnCreatePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnDeletePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnUpdatePreSecurity.class, fieldOrMethod); @@ -390,7 +400,7 @@ private void bindRelation(AccessibleObject fieldOrMethod, String fieldName, Clas relationshipsDeque.push(fieldName); fieldsToValues.put(fieldName, fieldOrMethod); - fieldsToTypes.put(fieldName, fieldType); + fieldsToTypes.put(fieldName, fieldType == null ? Void.class : fieldType); } private void bindAttr(AccessibleObject fieldOrMethod, String fieldName, Class fieldType) { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java index a8e37d846e..e0a275eec2 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java @@ -25,8 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import javax.persistence.Entity; - /** * Simple in-memory only database. */ @@ -44,18 +42,7 @@ public HashMapDataStore(Set beanPackages) { this.beanPackages = beanPackages; for (Package beanPackage : beanPackages) { - ClassScanner.getAnnotatedClasses(beanPackage, Include.class).stream() - .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) - .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, - Arrays.asList(Include.class, Exclude.class)) instanceof Include) - .forEach(modelClass -> dataStore.put(modelClass, - Collections.synchronizedMap(new LinkedHashMap<>()))); - } - - for (Package beanPackage : beanPackages) { - ClassScanner.getAnnotatedClasses(beanPackage, Entity.class).stream() - .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) - .filter(modelClass -> !dataStore.containsKey(modelClass)) + ClassScanner.getAllClasses(beanPackage.getName()).stream() .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, Arrays.asList(Include.class, Exclude.class)) instanceof Include) .forEach(modelClass -> dataStore.put(modelClass, From 4ee83c6113ab13d1186c3c6d85ce13ea7a05727f Mon Sep 17 00:00:00 2001 From: wcekan Date: Fri, 12 Mar 2021 08:31:18 -0500 Subject: [PATCH 4/6] migrate test from 5.x --- .../InMemoryStoreTransactionTest.java | 78 +++++++++++-------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java b/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java index 534272b771..6bddc6ee55 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransactionTest.java @@ -6,7 +6,6 @@ package com.yahoo.elide.core.datastore.inmemory; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -30,6 +29,7 @@ import com.yahoo.elide.core.sort.Sorting; import com.yahoo.elide.models.generics.Manager; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import example.Author; @@ -528,38 +528,48 @@ public void testInMemoryDataStore() { assertEquals(wrapped, wrapped.getDataStore()); - String tos = store.toString(); - assertTrue(tos.contains("Data store contents")); - assertTrue(tos.contains("Table class example.Author contents")); - assertTrue(tos.contains("Table class example.Book contents")); - assertTrue(tos.contains("Table class example.Child contents")); - assertTrue(tos.contains("Table class example.ComputedBean contents")); - assertTrue(tos.contains("Table class example.Editor contents")); - assertTrue(tos.contains("Table class example.FieldAnnotations contents")); - assertTrue(tos.contains("Table class example.FirstClassFields contents")); - assertTrue(tos.contains("Table class example.FunWithPermissions contents")); - assertTrue(tos.contains("Table class example.Invoice contents")); - assertTrue(tos.contains("Table class example.Job contents")); - assertTrue(tos.contains("Table class example.Left contents")); - assertTrue(tos.contains("Table class example.LineItem contents")); - assertTrue(tos.contains("Table class example.MapColorShape contents")); - assertTrue(tos.contains("Table class example.NoDeleteEntity contents")); - assertTrue(tos.contains("Table class example.NoReadEntity contents")); - assertTrue(tos.contains("Table class example.NoShareEntity contents")); - assertTrue(tos.contains("Table class example.NoUpdateEntity contents")); - assertTrue(tos.contains("Table class example.Parent contents")); - assertTrue(tos.contains("Table class example.Post contents")); - assertTrue(tos.contains("Table class example.PrimitiveId contents")); - assertTrue(tos.contains("Table class example.Publisher contents")); - assertTrue(tos.contains("Table class example.Right contents")); - assertTrue(tos.contains("Table class example.StringId contents")); - assertTrue(tos.contains("Table class example.UpdateAndCreate contents")); - assertTrue(tos.contains("Table class example.User contents")); - assertTrue(tos.contains("Table class example.packageshareable.ContainerWithPackageShare contents")); - assertTrue(tos.contains("Table class example.packageshareable.ShareableWithPackageShare contents")); - assertTrue(tos.contains("Table class example.packageshareable.UnshareableWithEntityUnshare contents")); - assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Employee contents")); - assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Manager contents")); - assertFalse(tos.contains("Table class com.yahoo.elide.models.generics.Other contents")); + // extract class names from DataStore string + String tos = store.toString() + .replace("Data store contents", "") + .replace("Table class ", "").replace(" contents", "") + .replace("Wrapped:[", "").replace("]", "") + .replace("\n\n", ",") + .replace(" ", "").replace("\n", ""); + + // make sure count is correct + assertEquals(ImmutableSet.copyOf(new String[] { + "example.Author", + "example.Book", + "example.Child", + "example.ComputedBean", + "example.Editor", + "example.FieldAnnotations", + "example.FirstClassFields", + "example.FunWithPermissions", + "example.Invoice", + "example.Job", + "example.Left", + "example.LineItem", + "example.MapColorShape", + "example.NoDeleteEntity", + "example.NoReadEntity", + "example.NoShareEntity", + "example.NoUpdateEntity", + "example.Parent", + "example.Post", + "example.PrimitiveId", + "example.Publisher", + "example.Right", + "example.StringId", + "example.UpdateAndCreate", + "example.User", + "example.packageshareable.ContainerWithPackageShare", + "example.packageshareable.ShareableWithPackageShare", + "example.packageshareable.UnshareableWithEntityUnshare", + "com.yahoo.elide.models.generics.Employee", + "com.yahoo.elide.models.generics.Manager", + "com.yahoo.elide.models.generics.Overlord", + "com.yahoo.elide.models.generics.Peon" + }), ImmutableSet.copyOf(tos.split(",")), String.join("\n", tos.split(","))); } } From f720136a3bffa03ee90d1fbe5f52a44d57c3d6dd Mon Sep 17 00:00:00 2001 From: wcekan Date: Wed, 17 Mar 2021 21:06:09 -0400 Subject: [PATCH 5/6] reverse --- .../main/java/com/yahoo/elide/core/EntityBinding.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java index 51de22288c..fd384b52b0 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java @@ -240,16 +240,6 @@ public List getAllFields() { */ private void bindEntityFields(Class cls, String type, Collection fieldOrMethodList) { for (AccessibleObject fieldOrMethod : fieldOrMethodList) { - // Special handling for Eclipse. Load missing annotations - if (fieldOrMethod.getAnnotations().length == 0 && fieldOrMethod instanceof Method) { - Method m = (Method) fieldOrMethod; - try { - fieldOrMethod = m.getDeclaringClass().getMethod(m.getName(), m.getParameterTypes()); - } catch (NoSuchMethodException | SecurityException e) { - // Not expected, leave alone - } - } - bindTriggerIfPresent(OnCreatePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnDeletePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnUpdatePreSecurity.class, fieldOrMethod); From 18d5e3b63d0bffbb90d0a7f6a647a24da1697d80 Mon Sep 17 00:00:00 2001 From: wcekan Date: Wed, 17 Mar 2021 22:11:12 -0400 Subject: [PATCH 6/6] revert to type if generics is unknown. --- .../java/com/yahoo/elide/core/EntityBinding.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java index fd384b52b0..e58a5d03b4 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java @@ -390,7 +390,7 @@ private void bindRelation(AccessibleObject fieldOrMethod, String fieldName, Clas relationshipsDeque.push(fieldName); fieldsToValues.put(fieldName, fieldOrMethod); - fieldsToTypes.put(fieldName, fieldType == null ? Void.class : fieldType); + fieldsToTypes.put(fieldName, fieldType); } private void bindAttr(AccessibleObject fieldOrMethod, String fieldName, Class fieldType) { @@ -481,6 +481,17 @@ public static Class getFieldType(Class parentClass, type = ((ParameterizedType) type).getActualTypeArguments()[index.get().intValue()]; } + Class cls = TypeUtils.getRawType(type, parentClass); + if (cls != null) { + return cls; + } + + if (fieldOrMethod instanceof Field) { + type = ((Field) fieldOrMethod).getType(); + } else { + type = ((Method) fieldOrMethod).getReturnType(); + } + return TypeUtils.getRawType(type, parentClass); }