Skip to content

Commit a7820c8

Browse files
committed
DATACMNS-309 - Fixed lookup of nested properties on TypeDiscoverer.
So far the property lookup of a nested property path (e.g. "foo.bar") failed in cases the head property was not cached already. We now recursively resolve the type information even for an unpopulated cache.
1 parent 64dada5 commit a7820c8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/main/java/org/springframework/data/util/TypeDiscoverer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2012 the original author or authors.
2+
* Copyright 2011-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -177,7 +177,7 @@ public TypeInformation<?> getProperty(String fieldname) {
177177
}
178178

179179
String head = fieldname.substring(0, separatorIndex);
180-
TypeInformation<?> info = fieldTypes.get(head);
180+
TypeInformation<?> info = getProperty(head);
181181
return info == null ? null : info.getProperty(fieldname.substring(separatorIndex + 1));
182182
}
183183

src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011 the original author or authors.
2+
* Copyright 2011-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -263,6 +263,20 @@ public void returnsComponentTypeForMultiDimensionalArrayCorrectly() {
263263
assertThat(information.getActualType().getActualType().getType(), is((Object) String.class));
264264
}
265265

266+
/**
267+
* @see DATACMNS-309
268+
*/
269+
@Test
270+
@SuppressWarnings("rawtypes")
271+
public void findsGetterOnInterface() {
272+
273+
TypeInformation<Product> information = from(Product.class);
274+
TypeInformation<?> categoryIdInfo = information.getProperty("category.id");
275+
276+
assertThat(categoryIdInfo, is(notNullValue()));
277+
assertThat(categoryIdInfo, is((TypeInformation) from(Long.class)));
278+
}
279+
266280
static class StringMapContainer extends MapContainer<String> {
267281

268282
}
@@ -375,4 +389,13 @@ class StringImplementation implements GenericInterface<String> {
375389
class LongImplementation implements GenericInterface<Long> {
376390

377391
}
392+
393+
interface Product {
394+
Category getCategory();
395+
}
396+
397+
interface Category {
398+
399+
Long getId();
400+
}
378401
}

0 commit comments

Comments
 (0)