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