Skip to content

Commit b3e1601

Browse files
committed
DATACMNS-1198 - Added PropertyPath.getLeafType() to expose leaf-property type.
1 parent d2008ea commit b3e1601

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ public PropertyPath getLeafProperty() {
132132
return result;
133133
}
134134

135+
/**
136+
* Returns the type of the leaf property of the current {@link PropertyPath}.
137+
*
138+
* @return will never be {@literal null}.
139+
*/
140+
public Class<?> getLeafType() {
141+
return getLeafProperty().getType();
142+
}
143+
135144
/**
136145
* Returns the type of the property will return the plain resolved type for simple properties, the component type for
137146
* any {@link Iterable} or the value type of a {@link java.util.Map} if the property is one.

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ public void cachesPropertyPathsByPathAndType() {
350350
assertThat(from("userName", Foo.class)).isSameAs(from("userName", Foo.class));
351351
}
352352

353+
@Test // DATACMNS-1198
354+
public void exposesLeafPropertyType() {
355+
assertThat(from("user.name", Bar.class).getLeafType()).isEqualTo(String.class);
356+
}
357+
353358
private class Foo {
354359

355360
String userName;

0 commit comments

Comments
 (0)