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 ;
@@ -219,12 +220,14 @@ public List<String> getInputProperties() {
219220	 * A {@link ReturnedType} that's backed by an actual class. 
220221	 * 
221222	 * @author Oliver Gierke 
223+ 	 * @author Mikhail Polivakha 
222224	 * @since 1.12 
223225	 */ 
224226	private  static  final  class  ReturnedClass  extends  ReturnedType  {
225227
226228		private  static  final  Set <Class <?>> VOID_TYPES  = new  HashSet <>(Arrays .asList (Void .class , void .class ));
227229
230+ 		private  final  Lazy <Boolean > isDto ;
228231		private  final  Class <?> type ;
229232		private  final  List <String > inputProperties ;
230233
@@ -243,6 +246,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
243246			Assert .isTrue (!returnedType .isInterface (), "Returned type must not be an interface" );
244247
245248			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+ 			);
246258			this .inputProperties  = detectConstructorParameterNames (returnedType );
247259		}
248260
@@ -294,13 +306,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
294306		}
295307
296308		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 ();
304310		}
305311
306312		private  boolean  isDomainSubtype () {
0 commit comments