diff options
-rw-r--r-- | server/src/main/java/com/vaadin/data/BeanBinderPropertySet.java | 9 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BeanBinderPropertySetTest.java | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/BeanBinderPropertySet.java b/server/src/main/java/com/vaadin/data/BeanBinderPropertySet.java index c167229f8c..f28873438e 100644 --- a/server/src/main/java/com/vaadin/data/BeanBinderPropertySet.java +++ b/server/src/main/java/com/vaadin/data/BeanBinderPropertySet.java @@ -195,7 +195,7 @@ public class BeanBinderPropertySet<T> implements BinderPropertySet<T> { try { definitions = BeanUtil.getBeanPropertyDescriptors(beanType).stream() - .filter(BeanBinderPropertySet::hasReadMethod) + .filter(BeanBinderPropertySet::hasNonObjectReadMethod) .map(descriptor -> new BeanBinderPropertyDefinition<>(this, descriptor)) .collect(Collectors.toMap(BinderPropertyDefinition::getName, @@ -234,8 +234,11 @@ public class BeanBinderPropertySet<T> implements BinderPropertySet<T> { return Optional.ofNullable(definitions.get(name)); } - private static boolean hasReadMethod(PropertyDescriptor descriptor) { - return descriptor.getReadMethod() != null; + private static boolean hasNonObjectReadMethod( + PropertyDescriptor descriptor) { + Method readMethod = descriptor.getReadMethod(); + return readMethod != null + && readMethod.getDeclaringClass() != Object.class; } private static Object invokeWrapExceptions(Method method, Object target, diff --git a/server/src/test/java/com/vaadin/data/BeanBinderPropertySetTest.java b/server/src/test/java/com/vaadin/data/BeanBinderPropertySetTest.java index 1fa431ac20..cf56dd9368 100644 --- a/server/src/test/java/com/vaadin/data/BeanBinderPropertySetTest.java +++ b/server/src/test/java/com/vaadin/data/BeanBinderPropertySetTest.java @@ -20,7 +20,11 @@ import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.HashSet; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.Assert; import org.junit.Test; @@ -98,4 +102,16 @@ public class BeanBinderPropertySetTest { deserializedDefinition); } + @Test + public void properties() { + BinderPropertySet<Person> propertySet = BeanBinderPropertySet + .get(Person.class); + + Set<String> propertyNames = propertySet.getProperties() + .map(BinderPropertyDefinition::getName) + .collect(Collectors.toSet()); + + Assert.assertEquals(new HashSet<>(Arrays.asList("name", "born")), + propertyNames); + } } |