Skip to content

Commit 1c136dc

Browse files
committed
Added Lazy wrapper for isDto check
1 parent d632d71 commit 1c136dc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public Class<?> getType() {
7474

7575
public List<PropertyDescriptor> getInputProperties() {
7676

77-
return properties.stream()//
78-
.filter(this::isInputProperty)//
79-
.distinct()//
77+
return properties.stream() //
78+
.filter(this::isInputProperty) //
79+
.distinct() //
8080
.collect(Collectors.toList());
8181
}
8282

src/main/java/org/springframework/data/repository/query/ReturnedType.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
3030
import org.springframework.data.projection.ProjectionFactory;
3131
import org.springframework.data.projection.ProjectionInformation;
32+
import org.springframework.data.util.Lazy;
3233
import org.springframework.lang.NonNull;
3334
import org.springframework.lang.Nullable;
3435
import 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

Comments
 (0)