DATACMNS-1738 - Expose method to obtain the repository query method return type.
We now expose RepositoryMetadata.getReturnType(…) to obtain the declared method return type. While pure Java code can rely on Method.getReturnType(), suspended Kotlin methods (Coroutines) require additional lookups. This is because the Kotlin compiler messes around with the return type in the bytecode. It changes the return type to java.lang.Object while synthesizing an additional method argument:
interface MyCoroutineRepository : Repository<Person, String> {
suspend fun suspendedQueryMethod(): Flow<Person>
}
compiles to
interface MyCoroutineRepository extends Repository<Person, String> {
Object suspendedQueryMethod(Continuation<Flow<Person>> arg0);
}
Therefore, the triviality of obtaining a return type becomes an inspection of the actual method arguments.
Related ticket: https://jira.spring.io/browse/DATAMONGO-2562
This commit is contained in:
@@ -22,6 +22,7 @@ import org.springframework.data.repository.core.CrudMethods;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
public final class DummyRepositoryInformation implements RepositoryInformation {
|
||||
|
||||
@@ -47,6 +48,11 @@ public final class DummyRepositoryInformation implements RepositoryInformation {
|
||||
return metadata.getRepositoryInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInformation<?> getReturnType(Method method) {
|
||||
return metadata.getReturnType(method);
|
||||
}
|
||||
|
||||
public Class<?> getReturnedDomainClass(Method method) {
|
||||
return getDomainType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user