Skip to content

Commit

Permalink
Added Lazy wrapper for ReturnType#isDto.
Browse files Browse the repository at this point in the history
Closes #3160
  • Loading branch information
mipo256 authored and mp911de committed Sep 26, 2024
1 parent 5df841b commit 4a620ed
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.ProjectionInformation;
import org.springframework.data.util.Lazy;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -219,12 +220,14 @@ public List<String> getInputProperties() {
* A {@link ReturnedType} that's backed by an actual class.
*
* @author Oliver Gierke
* @author Mikhail Polivakha
* @since 1.12
*/
private static final class ReturnedClass extends ReturnedType {

private static final Set<Class<?>> VOID_TYPES = new HashSet<>(Arrays.asList(Void.class, void.class));

private final Lazy<Boolean> isDto;
private final Class<?> type;
private final List<String> inputProperties;

Expand All @@ -243,6 +246,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
Assert.isTrue(!returnedType.isInterface(), "Returned type must not be an interface");

this.type = returnedType;
this.isDto = Lazy.of(() ->
!Object.class.equals(type) && //
!type.isEnum() && //
!isDomainSubtype() && //
!isPrimitiveOrWrapper() && //
!Number.class.isAssignableFrom(type) && //
!VOID_TYPES.contains(type) && //
!type.getPackage().getName().startsWith("java.")
);
this.inputProperties = detectConstructorParameterNames(returnedType);
}

Expand Down Expand Up @@ -294,13 +306,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
}

private boolean isDto() {
return !Object.class.equals(type) && //
!type.isEnum() && //
!isDomainSubtype() && //
!isPrimitiveOrWrapper() && //
!Number.class.isAssignableFrom(type) && //
!VOID_TYPES.contains(type) && //
!type.getPackage().getName().startsWith("java.");
return isDto.get();
}

private boolean isDomainSubtype() {
Expand Down

0 comments on commit 4a620ed

Please sign in to comment.