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 ;
@@ -218,12 +219,14 @@ public List<String> getInputProperties() {
218219	 * A {@link ReturnedType} that's backed by an actual class. 
219220	 * 
220221	 * @author Oliver Gierke 
222+ 	 * @author Mikhail Polivakha 
221223	 * @since 1.12 
222224	 */ 
223225	private  static  final  class  ReturnedClass  extends  ReturnedType  {
224226
225227		private  static  final  Set <Class <?>> VOID_TYPES  = new  HashSet <>(Arrays .asList (Void .class , void .class ));
226228
229+ 		private  final  Lazy <Boolean > isDto ;
227230		private  final  Class <?> type ;
228231		private  final  List <String > inputProperties ;
229232
@@ -242,6 +245,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
242245			Assert .isTrue (!returnedType .isInterface (), "Returned type must not be an interface" );
243246
244247			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+ 			);
245257			this .inputProperties  = detectConstructorParameterNames (returnedType );
246258		}
247259
@@ -293,13 +305,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
293305		}
294306
295307		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 ();
303309		}
304310
305311		private  boolean  isDomainSubtype () {
0 commit comments