File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed
main/java/org/springframework/data/repository/core/support
test/java/org/springframework/data/repository/core/support Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -57,14 +57,7 @@ public AbstractRepositoryMetadata(Class<?> repositoryInterface) {
57
57
* @see org.springframework.data.repository.core.RepositoryMetadata#getReturnedDomainClass(java.lang.reflect.Method)
58
58
*/
59
59
public Class <?> getReturnedDomainClass (Method method ) {
60
-
61
- TypeInformation <?> returnTypeInfo = typeInformation .getReturnType (method );
62
- Class <?> rawType = returnTypeInfo .getType ();
63
-
64
- boolean needToUnwrap = Iterable .class .isAssignableFrom (rawType ) || rawType .isArray ()
65
- || QueryExecutionConverters .supports (rawType );
66
-
67
- return needToUnwrap ? returnTypeInfo .getComponentType ().getType () : rawType ;
60
+ return unwrapWrapperTypes (typeInformation .getReturnType (method ));
68
61
}
69
62
70
63
/*
@@ -104,4 +97,20 @@ public boolean isPagingRepository() {
104
97
105
98
return Arrays .asList (findAllMethod .getParameterTypes ()).contains (Pageable .class );
106
99
}
100
+
101
+ /**
102
+ * Recursively unwraps well known wrapper types from the given {@link TypeInformation}.
103
+ *
104
+ * @param type must not be {@literal null}.
105
+ * @return
106
+ */
107
+ private static Class <?> unwrapWrapperTypes (TypeInformation <?> type ) {
108
+
109
+ Class <?> rawType = type .getType ();
110
+
111
+ boolean needToUnwrap = Iterable .class .isAssignableFrom (rawType ) || rawType .isArray ()
112
+ || QueryExecutionConverters .supports (rawType );
113
+
114
+ return needToUnwrap ? unwrapWrapperTypes (type .getComponentType ()) : rawType ;
115
+ }
107
116
}
Original file line number Diff line number Diff line change @@ -117,6 +117,18 @@ public void discoversDomainTypeOnReturnTypeWrapper() throws Exception {
117
117
assertThat (metadata .getReturnedDomainClass (method ), is (typeCompatibleWith (User .class )));
118
118
}
119
119
120
+ /**
121
+ * @see DATACMNS-483
122
+ */
123
+ @ Test
124
+ public void discoversDomainTypeOnNestedReturnTypeWrapper () throws Exception {
125
+
126
+ RepositoryMetadata metadata = new DefaultRepositoryMetadata (OptionalRepository .class );
127
+
128
+ Method method = OptionalRepository .class .getMethod ("findByLastname" , String .class );
129
+ assertThat (metadata .getReturnedDomainClass (method ), is (typeCompatibleWith (User .class )));
130
+ }
131
+
120
132
@ SuppressWarnings ("unused" )
121
133
private class User {
122
134
@@ -187,5 +199,8 @@ static interface ConcreteRepository extends IdTypeFixingRepository<User> {
187
199
static interface OptionalRepository extends Repository <User , Long > {
188
200
189
201
Optional <User > findByEmailAddress (String emailAddress );
202
+
203
+ // Contrived example but to make sure recursive wrapper resolution works
204
+ Optional <Optional <User >> findByLastname (String lastname );
190
205
}
191
206
}
You can’t perform that action at this time.
0 commit comments