From c5238bc5fb2e8cdaa5debc01ee247d3356033e70 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 12 Jan 2021 15:47:00 +0100 Subject: [PATCH] Polishing. Reuse definitive path flag without recompile the expression. See #2270 --- .../data/web/JsonProjectingMethodInterceptorFactory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java b/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java index 8ae20805c..3b1262b35 100644 --- a/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java +++ b/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java @@ -156,13 +156,14 @@ public class JsonProjectingMethodInterceptorFactory implements MethodInterceptor return isCollectionResult && !(nested instanceof Collection) ? result : nested; } - type = isCollectionResult && JsonPath.isPathDefinite(jsonPath) + boolean definitePath = JsonPath.isPathDefinite(jsonPath); + type = isCollectionResult && definitePath ? ResolvableType.forClassWithGenerics(List.class, type) : type; List result = (List) context.read(jsonPath, new ResolvableTypeRef(type)); - if (isCollectionResult && JsonPath.isPathDefinite(jsonPath)) { + if (isCollectionResult && definitePath) { result = (List) result.get(0); }