Browse Source

Consistently apply method ordering in DefaultProjectionInformation.

Fixes #2718.

$ Conflicts:
$	src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java
pull/2772/head
Oliver Drotbohm 3 years ago
parent
commit
0eeaa63eed
No known key found for this signature in database
GPG Key ID: C25FBFA0DA493A1D
  1. 20
      src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java

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

@ -29,7 +29,6 @@ import java.util.stream.Stream; @@ -29,7 +29,6 @@ import java.util.stream.Stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.core.type.MethodMetadata;
@ -171,7 +170,7 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -171,7 +170,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
Stream<PropertyDescriptor> allButDefaultGetters = Arrays.stream(BeanUtils.getPropertyDescriptors(type)) //
.filter(it -> !hasDefaultGetter(it));
Stream<PropertyDescriptor> ownDescriptors = metadata.map(it -> filterAndOrder(allButDefaultGetters, it))
Stream<PropertyDescriptor> ownDescriptors = metadata.map(it -> filterAndOrder(allButDefaultGetters, it)) //
.orElse(allButDefaultGetters);
Stream<PropertyDescriptor> superTypeDescriptors = metadata.map(this::fromMetadata) //
@ -189,18 +188,16 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -189,18 +188,16 @@ class DefaultProjectionInformation implements ProjectionInformation {
* @param metadata must not be {@literal null}.
* @return
*/
private static Stream<PropertyDescriptor> filterAndOrder(Stream<PropertyDescriptor> source,
MethodsMetadata metadata) {
private Stream<PropertyDescriptor> filterAndOrder(Stream<PropertyDescriptor> source, MethodsMetadata metadata) {
Map<String, Integer> orderedMethods = getMethodOrder(metadata);
if (orderedMethods.isEmpty()) {
return source;
}
Stream<PropertyDescriptor> filtered = source.filter(it -> it.getReadMethod() != null)
.filter(it -> it.getReadMethod().getDeclaringClass().equals(type));
return source.filter(descriptor -> descriptor.getReadMethod() != null)
.filter(descriptor -> orderedMethods.containsKey(descriptor.getReadMethod().getName()))
.sorted(Comparator.comparingInt(left -> orderedMethods.get(left.getReadMethod().getName())));
return orderedMethods.isEmpty()
? filtered
: filtered.sorted(Comparator.comparingInt(left -> orderedMethods.get(left.getReadMethod().getName())));
}
/**
@ -240,7 +237,8 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -240,7 +237,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
} catch (IOException e) {
logger.info(LogMessage.format("Couldn't read class metadata for %s. Input property calculation might fail", type));
logger.info(
LogMessage.format("Couldn't read class metadata for %s. Input property calculation might fail", type));
return Optional.empty();
}
}

Loading…
Cancel
Save