public Class<?> getReturnedDomainClass(Method method) { return QueryExecutionConverters.unwrapWrapperTypes(typeInformation.getReturnType(method)).getType(); }
/** * Recursively unwraps well known wrapper types from the given {@link TypeInformation}. * * @param type must not be {@literal null}. * @return will never be {@literal null}. */ public static TypeInformation<?> unwrapWrapperTypes(TypeInformation<?> type) { Assert.notNull(type, "type must not be null"); Class<?> rawType = type.getType(); boolean needToUnwrap = type.isCollectionLike() // || Slice.class.isAssignableFrom(rawType) // || GeoResults.class.isAssignableFrom(rawType) // || rawType.isArray() // || supports(rawType) // || Stream.class.isAssignableFrom(rawType); return needToUnwrap ? unwrapWrapperTypes(type.getRequiredComponentType()) : type; }
/** * Returns whether the given {@link MethodParameter} is a dynamic projection parameter, which means it carries a * dynamic type parameter which is identical to the type parameter of the actually returned type. * <p> * <code> * <T> Collection<T> findBy…(…, Class<T> type); * </code> * * @param parameter must not be {@literal null}. * @return */ private static boolean isDynamicProjectionParameter(MethodParameter parameter) { Method method = parameter.getMethod(); if (method == null) { throw new IllegalStateException(String.format("Method parameter %s is not backed by a method!", parameter)); } ClassTypeInformation<?> ownerType = ClassTypeInformation.from(parameter.getDeclaringClass()); TypeInformation<?> parameterTypes = ownerType.getParameterTypes(method).get(parameter.getParameterIndex()); if (!parameterTypes.getType().equals(Class.class)) { return false; } TypeInformation<?> bound = parameterTypes.getTypeArguments().get(0); TypeInformation<Object> returnType = ClassTypeInformation.fromReturnTypeOf(method); return bound.equals(QueryExecutionConverters.unwrapWrapperTypes(returnType)); }