2929import org .springframework .data .mapping .model .PreferredConstructorDiscoverer ;
3030import org .springframework .data .projection .ProjectionFactory ;
3131import org .springframework .data .projection .ProjectionInformation ;
32+ import org .springframework .data .util .Lazy ;
3233import org .springframework .lang .NonNull ;
3334import org .springframework .lang .Nullable ;
3435import org .springframework .util .Assert ;
@@ -205,6 +206,8 @@ private static final class ReturnedClass extends ReturnedType {
205206 private static final Set <Class <?>> VOID_TYPES = new HashSet <>(Arrays .asList (Void .class , void .class ));
206207
207208 private final Class <?> type ;
209+
210+ private final Lazy <Boolean > isDto ;
208211 private final List <String > inputProperties ;
209212
210213 /**
@@ -222,6 +225,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
222225 Assert .isTrue (!returnedType .isInterface (), "Returned type must not be an interface" );
223226
224227 this .type = returnedType ;
228+ this .isDto = Lazy .of (() ->
229+ !Object .class .equals (type ) && //
230+ !type .isEnum () && //
231+ !isDomainSubtype () && //
232+ !isPrimitiveOrWrapper () && //
233+ !Number .class .isAssignableFrom (type ) && //
234+ !VOID_TYPES .contains (type ) && //
235+ !type .getPackage ().getName ().startsWith ("java." )
236+ );
225237 this .inputProperties = detectConstructorParameterNames (returnedType );
226238 }
227239
@@ -271,13 +283,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
271283 }
272284
273285 private boolean isDto () {
274- return !Object .class .equals (type ) && //
275- !type .isEnum () && //
276- !isDomainSubtype () && //
277- !isPrimitiveOrWrapper () && //
278- !Number .class .isAssignableFrom (type ) && //
279- !VOID_TYPES .contains (type ) && //
280- !type .getPackage ().getName ().startsWith ("java." );
286+ return isDto .get ();
281287 }
282288
283289 private boolean isDomainSubtype () {
0 commit comments