File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
main/java/org/springframework/data/mapping
test/java/org/springframework/data/mapping Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,21 @@ public boolean isCollection() {
195
195
return isCollection ;
196
196
}
197
197
198
+ /**
199
+ * Returns the {@link PropertyPath} for the path nested under the current property.
200
+ *
201
+ * @param path must not be {@literal null} or empty.
202
+ * @return will never be {@literal null}.
203
+ */
204
+ public PropertyPath nested (String path ) {
205
+
206
+ Assert .hasText (path , "Path must not be null or empty!" );
207
+
208
+ String lookup = toDotPath ().concat ("." ).concat (path );
209
+
210
+ return PropertyPath .from (lookup , owningType );
211
+ }
212
+
198
213
/*
199
214
* (non-Javadoc)
200
215
* @see java.lang.Iterable#iterator()
Original file line number Diff line number Diff line change @@ -355,6 +355,20 @@ public void exposesLeafPropertyType() {
355
355
assertThat (from ("user.name" , Bar .class ).getLeafType ()).isEqualTo (String .class );
356
356
}
357
357
358
+ @ Test // DATACMNS-1199
359
+ public void createsNestedPropertyPath () {
360
+ assertThat (from ("user" , Bar .class ).nested ("name" )).isEqualTo (from ("user.name" , Bar .class ));
361
+ }
362
+
363
+ @ Test // DATACMNS-1199
364
+ public void rejectsNonExistantNestedPath () {
365
+
366
+ assertThatExceptionOfType (PropertyReferenceException .class ) //
367
+ .isThrownBy (() -> from ("user" , Bar .class ).nested ("nonexistant" )) //
368
+ .withMessageContaining ("nonexistant" ) //
369
+ .withMessageContaining ("Bar.user" );
370
+ }
371
+
358
372
private class Foo {
359
373
360
374
String userName ;
You can’t perform that action at this time.
0 commit comments