diff --git a/src/main/java/org/springframework/data/mapping/PersistentProperty.java b/src/main/java/org/springframework/data/mapping/PersistentProperty.java index 378937fb4..5ffd7c4d0 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/PersistentProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 the original author or authors. + * Copyright 2011-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,4 +171,12 @@ public interface PersistentProperty
> { * @return the map's value type or {@literal null} if no {@link java.util.Map} */ Class> getMapValueType(); + + /** + * Returns the actual type of the property. This will be the original property type if no generics were used, the + * component type for collection-like types and arrays as well as the value type for map properties. + * + * @return + */ + Class> getActualType(); } 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 d05ab08db..87bb00e35 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 the original author or authors. + * Copyright 2011-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -282,6 +282,15 @@ public abstract class AbstractPersistentProperty
return isMap() ? information.getMapValueType().getType() : null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.mapping.PersistentProperty#getActualType()
+ */
+ @Override
+ public Class> getActualType() {
+ return information.getActualType().getType();
+ }
+
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
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 e8d6f1628..543bba92b 100644
--- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
+++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2012 the original author or authors.
+ * Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.junit.Test;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
+import org.springframework.data.mapping.Person;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
@@ -214,6 +215,34 @@ public class AbstractPersistentPropertyUnitTests {
}
}
+ /**
+ * @see DATACMNS-337
+ */
+ @Test
+ public void resolvesActualType() {
+
+ SamplePersistentProperty property = getProperty(Sample.class, "person");
+ assertThat(property.getActualType(), is((Object) Person.class));
+
+ property = getProperty(Sample.class, "persons");
+ assertThat(property.getActualType(), is((Object) Person.class));
+
+ property = getProperty(Sample.class, "personArray");
+ assertThat(property.getActualType(), is((Object) Person.class));
+
+ property = getProperty(Sample.class, "personMap");
+ assertThat(property.getActualType(), is((Object) Person.class));
+ }
+
+ private