29
29
import org .springframework .data .mapping .model .PreferredConstructorDiscoverer ;
30
30
import org .springframework .data .projection .ProjectionFactory ;
31
31
import org .springframework .data .projection .ProjectionInformation ;
32
+ import org .springframework .data .util .Lazy ;
32
33
import org .springframework .lang .NonNull ;
33
34
import org .springframework .lang .Nullable ;
34
35
import org .springframework .util .Assert ;
@@ -219,12 +220,14 @@ public List<String> getInputProperties() {
219
220
* A {@link ReturnedType} that's backed by an actual class.
220
221
*
221
222
* @author Oliver Gierke
223
+ * @author Mikhail Polivakha
222
224
* @since 1.12
223
225
*/
224
226
private static final class ReturnedClass extends ReturnedType {
225
227
226
228
private static final Set <Class <?>> VOID_TYPES = new HashSet <>(Arrays .asList (Void .class , void .class ));
227
229
230
+ private final Lazy <Boolean > isDto ;
228
231
private final Class <?> type ;
229
232
private final List <String > inputProperties ;
230
233
@@ -243,6 +246,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
243
246
Assert .isTrue (!returnedType .isInterface (), "Returned type must not be an interface" );
244
247
245
248
this .type = returnedType ;
249
+ this .isDto = Lazy .of (() ->
250
+ !Object .class .equals (type ) && //
251
+ !type .isEnum () && //
252
+ !isDomainSubtype () && //
253
+ !isPrimitiveOrWrapper () && //
254
+ !Number .class .isAssignableFrom (type ) && //
255
+ !VOID_TYPES .contains (type ) && //
256
+ !type .getPackage ().getName ().startsWith ("java." )
257
+ );
246
258
this .inputProperties = detectConstructorParameterNames (returnedType );
247
259
}
248
260
@@ -294,13 +306,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
294
306
}
295
307
296
308
private boolean isDto () {
297
- return !Object .class .equals (type ) && //
298
- !type .isEnum () && //
299
- !isDomainSubtype () && //
300
- !isPrimitiveOrWrapper () && //
301
- !Number .class .isAssignableFrom (type ) && //
302
- !VOID_TYPES .contains (type ) && //
303
- !type .getPackage ().getName ().startsWith ("java." );
309
+ return isDto .get ();
304
310
}
305
311
306
312
private boolean isDomainSubtype () {
0 commit comments