Skip to content

Commit c8fb117

Browse files
committed
DATACMNS-963 - Returned type returns distinct input properties now.
We now manually filter already gathered property names in ReturnedInterface.getInputProperties() as we have to deal with duplications for properties with the same name at different levels of the inheritance hierarchy.
1 parent f4e9c2c commit c8fb117

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/org/springframework/data/repository/query/ReturnedType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public List<String> getInputProperties() {
191191
List<String> properties = new ArrayList<String>();
192192

193193
for (PropertyDescriptor descriptor : information.getInputProperties()) {
194-
properties.add(descriptor.getName());
194+
if (!properties.contains(descriptor.getName())) {
195+
properties.add(descriptor.getName());
196+
}
195197
}
196198

197199
return properties;

src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ public void considersInterfaceImplementedByDomainTypeNotProjecting() throws Exce
179179
assertThat(type.isProjecting(), is(false));
180180
}
181181

182+
/**
183+
* @see DATACMNS-963
184+
*/
185+
@Test
186+
public void detectsDistinctInputProperties() {
187+
188+
ReturnedType type = ReturnedType.of(Child.class, Object.class, new SpelAwareProxyProjectionFactory());
189+
190+
List<String> properties = type.getInputProperties();
191+
192+
assertThat(properties, hasSize(1));
193+
assertThat(properties, contains("firstname"));
194+
}
195+
182196
private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
183197
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
184198
}
@@ -262,4 +276,12 @@ interface OpenProjection {
262276
@Value("#{target.firstname + ' ' + target.lastname}")
263277
String getFullName();
264278
}
279+
280+
static interface Parent {
281+
String getFirstname();
282+
}
283+
284+
static interface Child extends Parent {
285+
String getFirstname();
286+
}
265287
}

0 commit comments

Comments
 (0)