1
1
/*
2
- * Copyright 2008-2013 the original author or authors.
2
+ * Copyright 2008-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import java .util .Collection ;
22
22
23
23
import org .springframework .data .repository .Repository ;
24
+ import org .springframework .data .util .ClassTypeInformation ;
25
+ import org .springframework .data .util .TypeInformation ;
26
+ import org .springframework .util .Assert ;
24
27
import org .springframework .util .ReflectionUtils ;
25
28
import org .springframework .util .StringUtils ;
26
29
@@ -34,9 +37,7 @@ public abstract class ClassUtils {
34
37
/**
35
38
* Private constructor to prevent instantiation.
36
39
*/
37
- private ClassUtils () {
38
-
39
- }
40
+ private ClassUtils () {}
40
41
41
42
/**
42
43
* Returns whether the given class contains a property with the given name.
@@ -96,15 +97,22 @@ public static int getNumberOfOccurences(Method method, Class<?> type) {
96
97
}
97
98
98
99
/**
99
- * Asserts the given {@link Method}'s return type to be one of the given types.
100
+ * Asserts the given {@link Method}'s return type to be one of the given types. Will unwrap known wrapper types before
101
+ * the assignment check (see {@link QueryExecutionConverters}).
100
102
*
101
- * @param method
102
- * @param types
103
+ * @param method must not be {@literal null}.
104
+ * @param types must not be {@literal null} or empty.
103
105
*/
104
106
public static void assertReturnTypeAssignable (Method method , Class <?>... types ) {
105
107
108
+ Assert .notNull (method , "Method must not be null!" );
109
+ Assert .notEmpty (types , "Types must not be null or empty!" );
110
+
111
+ TypeInformation <?> returnType = ClassTypeInformation .fromReturnTypeOf (method );
112
+ returnType = QueryExecutionConverters .supports (returnType .getType ()) ? returnType .getComponentType () : returnType ;
113
+
106
114
for (Class <?> type : types ) {
107
- if (type .isAssignableFrom (method . getReturnType ())) {
115
+ if (type .isAssignableFrom (returnType . getType ())) {
108
116
return ;
109
117
}
110
118
}
0 commit comments