Correctly unwrap nested JSON array projections.

We now check for double-nesting of JSON path evaluation results when the return type is a collection. If the result is double-wrapped and the nested object is a collection then we unwrap it.

Closes #2270
This commit is contained in:
Mark Paluch
2021-01-12 15:46:17 +01:00
parent 2bf5e53a3b
commit 037df8e3ae
2 changed files with 43 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ import com.jayway.jsonpath.spi.mapper.MappingProvider;
* {@link MethodInterceptorFactory} to create a {@link MethodInterceptor} that will
*
* @author Oliver Gierke
* @author Mark Paluch
* @soundtrack Jeff Coffin - Fruitcake (The Inside Of The Outside)
* @since 1.13
*/
@@ -152,7 +153,9 @@ public class JsonProjectingMethodInterceptorFactory implements MethodInterceptor
if (returnType.getRequiredActualType().getType().isInterface()) {
List<?> result = context.read(jsonPath);
return result.isEmpty() ? null : result.get(0);
Object nested = result.isEmpty() ? null : result.get(0);
return isCollectionResult && !(nested instanceof Collection) ? result : nested;
}
type = isCollectionResult && JsonPath.isPathDefinite(jsonPath)