DATACMNS-917 - Query method execution for Maps now defaults null to an empty Map.
QueryExecutionResultHandler now explicitly handles null values for query methods returning Maps by returning an empty Map. This can be the case if a query is supposed to produce a Map (a single result) but doesn't actually yield any results at all.
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
@@ -68,11 +71,15 @@ class QueryExecutionResultHandler {
|
||||
return conversionService.convert(new NullableWrapper(result), expectedReturnType);
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
return null;
|
||||
if (result != null) {
|
||||
return conversionService.canConvert(result.getClass(), expectedReturnType)
|
||||
? conversionService.convert(result, expectedReturnType) : result;
|
||||
}
|
||||
|
||||
return conversionService.canConvert(result.getClass(), expectedReturnType) ? conversionService.convert(result,
|
||||
expectedReturnType) : result;
|
||||
if (Map.class.equals(expectedReturnType)) {
|
||||
return CollectionFactory.createMap(expectedReturnType, 0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user