diff --git a/src/main/java/org/springframework/data/mapping/PropertyPath.java b/src/main/java/org/springframework/data/mapping/PropertyPath.java index 920488699..7596792ed 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -132,6 +132,15 @@ public class PropertyPath implements Streamable { return result; } + /** + * Returns the type of the leaf property of the current {@link PropertyPath}. + * + * @return will never be {@literal null}. + */ + public Class getLeafType() { + return getLeafProperty().getType(); + } + /** * Returns the type of the property will return the plain resolved type for simple properties, the component type for * any {@link Iterable} or the value type of a {@link java.util.Map} if the property is one. diff --git a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java index 427de3510..c9653e288 100755 --- a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java @@ -350,6 +350,11 @@ public class PropertyPathUnitTests { assertThat(from("userName", Foo.class)).isSameAs(from("userName", Foo.class)); } + @Test // DATACMNS-1198 + public void exposesLeafPropertyType() { + assertThat(from("user.name", Bar.class).getLeafType()).isEqualTo(String.class); + } + private class Foo { String userName;