diff --git a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java index 023cdc5aa..03dfbb24d 100644 --- a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java +++ b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java @@ -66,12 +66,20 @@ class QueryExecutionResultHandler { Class expectedReturnType = returnTypeDescriptor.getType(); + // Early return if the raw value matches + if (result != null && expectedReturnType.isInstance(result)) { return result; } result = unwrapOptional(result); + // Early return if the unrwapped value matches + + if (result != null && expectedReturnType.isInstance(result)) { + return result; + } + if (QueryExecutionConverters.supports(expectedReturnType)) { TypeDescriptor targetType = TypeDescriptor.valueOf(expectedReturnType);