diff --git a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index 9e64ebfa8..e45d47b6b 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -61,15 +61,15 @@ public abstract class AbstractPersistentProperty
Assert.notNull(simpleTypeHolder, "SimpleTypeHolder must not be null!"); Assert.notNull(owner, "Owner entity must not be null!"); + this.propertyDescriptor = propertyDescriptor; + this.field = field; + this.owner = owner; + this.simpleTypeHolder = simpleTypeHolder; this.name = field == null ? propertyDescriptor.getName() : field.getName(); this.information = owner.getTypeInformation().getProperty(this.name); this.rawType = this.information != null ? information.getType() : field == null ? propertyDescriptor.getPropertyType() : field.getType(); - this.propertyDescriptor = propertyDescriptor; - this.field = field; this.association = isAssociation() ? createAssociation() : null; - this.owner = owner; - this.simpleTypeHolder = simpleTypeHolder; this.hashCode = this.field == null ? this.propertyDescriptor.hashCode() : this.field.hashCode(); } @@ -163,7 +163,11 @@ public abstract class AbstractPersistentProperty
return null; } - return rawType.isAssignableFrom(getter.getReturnType()) ? getter : null; + Class> returnType = owner.getTypeInformation() // + .getReturnType(getter) // + .getType(); + + return rawType.isAssignableFrom(returnType) ? getter : null; } /* @@ -183,7 +187,12 @@ public abstract class AbstractPersistentProperty
return null;
}
- return setter.getParameterTypes()[0].isAssignableFrom(rawType) ? setter : null;
+ Class> parameterType = owner.getTypeInformation() //
+ .getParameterTypes(setter) //
+ .get(0) //
+ .getType();
+
+ return parameterType.isAssignableFrom(rawType) ? setter : null;
}
/*
diff --git a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
index 65c8b494f..dac2eb2ac 100644
--- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
+++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
@@ -18,6 +18,9 @@ package org.springframework.data.mapping.model;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import lombok.Getter;
+import lombok.Setter;
+
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -208,6 +211,15 @@ public class AbstractPersistentPropertyUnitTests {
assertThat(property.getRawType(), is(typeCompatibleWith(String.class)));
}
+ @Test // DATACMNS-1180
+ public void returnsAccessorsForGenericReturnType() {
+
+ SamplePersistentProperty property = getProperty(ConcreteGetter.class, "genericField");
+
+ assertThat(property.getSetter(), is(notNullValue()));
+ assertThat(property.getGetter(), is(notNullValue()));
+ }
+
private