DATACMNS-862 - ReturnedInterface now considers interfaces implemented by the domain type.
We now check whether the interface return type is implemented by the domain type and opt out of all projection efforts if so.
This commit is contained in:
@@ -160,7 +160,7 @@ public abstract class ReturnedType {
|
||||
* @see org.springframework.data.repository.query.ReturnedType#needsCustomConstruction()
|
||||
*/
|
||||
public boolean needsCustomConstruction() {
|
||||
return information.isClosed();
|
||||
return isProjecting() && information.isClosed();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -169,7 +169,7 @@ public abstract class ReturnedType {
|
||||
*/
|
||||
@Override
|
||||
public boolean isProjecting() {
|
||||
return true;
|
||||
return !information.getType().isAssignableFrom(domainType);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -178,7 +178,7 @@ public abstract class ReturnedType {
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getTypeToRead() {
|
||||
return information.isClosed() ? null : domainType;
|
||||
return isProjecting() && information.isClosed() ? null : domainType;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -167,6 +167,18 @@ public class ReturnedTypeUnitTests {
|
||||
assertThat(type.isProjecting(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-862
|
||||
*/
|
||||
@Test
|
||||
public void considersInterfaceImplementedByDomainTypeNotProjecting() throws Exception {
|
||||
|
||||
ReturnedType type = getReturnedType("findOneInterface");
|
||||
|
||||
assertThat(type.needsCustomConstruction(), is(false));
|
||||
assertThat(type.isProjecting(), is(false));
|
||||
}
|
||||
|
||||
private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
|
||||
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
|
||||
}
|
||||
@@ -206,12 +218,16 @@ public class ReturnedTypeUnitTests {
|
||||
|
||||
LocalDateTime timeQuery();
|
||||
|
||||
SampleInterface findOneInterface();
|
||||
|
||||
static enum MyEnum {
|
||||
VALUE
|
||||
}
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
static interface SampleInterface {}
|
||||
|
||||
static class Sample implements SampleInterface {
|
||||
public String firstname, lastname;
|
||||
|
||||
public Sample(String firstname, String lastname) {
|
||||
|
||||
Reference in New Issue
Block a user