Skip to content

Commit 8eb2b14

Browse files
committed
GH-2421 - Improve property filter for projections.
Closes #2421
1 parent 4215593 commit 8eb2b14

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/PropertyFilter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.apiguardian.api.API;
1919
import org.springframework.data.mapping.PropertyPath;
20+
import org.springframework.util.StringUtils;
2021

2122
import java.util.HashSet;
2223
import java.util.Map;
@@ -79,10 +80,17 @@ public boolean contains(String dotPath, Class<?> typeToCheck) {
7980
return false;
8081
}
8182

82-
Optional<String> first = projectingPropertyPaths.keySet().stream().sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())).filter(dotPath::contains).findFirst();
83+
// create a sorted list of the deepest paths first
84+
Optional<String> candidate = projectingPropertyPaths.keySet().stream().sorted((o1, o2) -> {
85+
int depth1 = StringUtils.countOccurrencesOf(o1, ".");
86+
int depth2 = StringUtils.countOccurrencesOf(o2, ".");
8387

84-
return projectingPropertyPaths.containsKey(dotPath) ||
85-
(first.isPresent() && projectingPropertyPaths.get(first.get()));
88+
return Integer.compare(depth2, depth1);
89+
})
90+
.filter(d -> dotPath.contains(d) && dotPath.startsWith(d)).findFirst();
91+
92+
return projectingPropertyPaths.containsKey(dotPath)
93+
|| (dotPath.contains(".") && candidate.isPresent() && projectingPropertyPaths.get(candidate.get()));
8694
}
8795

8896
@Override

0 commit comments

Comments
 (0)