DATACMNS-840 - ReturnedClass now aborts parameter name detection for types with multiple constructors.
In case a DTO type exposes multiple no-argument constructors we now leniently abort the parameter name detection and let downstream users decide what to do in this particular case. The problematic case can't be outright rejected here already as there's valid scenarios for that, e.g. in JPA the type could be used for multiple query methods, using explict constructor expressions listing arguments explicitly and thereby select one of the multiple constructors.
This commit is contained in:
@@ -130,6 +130,17 @@ public class ReturnedTypeUnitTests {
|
||||
assertThat(type.getTypeToRead(), is(typeCompatibleWith(BigInteger.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-840
|
||||
*/
|
||||
@Test
|
||||
public void detectsSampleDtoWithDefaultConstructor() throws Exception {
|
||||
|
||||
ReturnedType type = getReturnedType("dtoWithMultipleConstructors");
|
||||
|
||||
assertThat(type.getInputProperties(), is(empty()));
|
||||
}
|
||||
|
||||
private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
|
||||
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
|
||||
}
|
||||
@@ -162,6 +173,8 @@ public class ReturnedTypeUnitTests {
|
||||
Page<SampleProjection> findPageProjection(Pageable pageable);
|
||||
|
||||
BigInteger countQuery();
|
||||
|
||||
SampleDtoWithMultipleConstructors dtoWithMultipleConstructors();
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
@@ -180,6 +193,13 @@ public class ReturnedTypeUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class SampleDtoWithMultipleConstructors {
|
||||
|
||||
SampleDtoWithMultipleConstructors(String firstname) {}
|
||||
|
||||
SampleDtoWithMultipleConstructors(int age) {}
|
||||
}
|
||||
|
||||
interface SampleProjection {
|
||||
|
||||
String getLastname();
|
||||
|
||||
Reference in New Issue
Block a user