Fix argument conversion in QuerydslPredicateBuilder.
We now consider the correct argument type instead of checking assignability of the actual property type against the input value. Closes: #2649 Original Pull Request: #2650
This commit is contained in:
committed by
Christoph Strobl
parent
54c9ddfcbb
commit
f7cdad92b0
@@ -176,30 +176,29 @@ public class QuerydslPredicateBuilder {
|
||||
*/
|
||||
private Collection<Object> convertToPropertyPathSpecificType(List<?> source, PathInformation path) {
|
||||
|
||||
Class<?> targetType = path.getLeafType();
|
||||
|
||||
if (source.isEmpty() || isSingleElementCollectionWithEmptyItem(source)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
TypeDescriptor targetType = getTargetTypeDescriptor(path);
|
||||
Collection<Object> target = new ArrayList<>(source.size());
|
||||
|
||||
for (Object value : source) {
|
||||
target.add(getValue(path, targetType, value));
|
||||
target.add(getValue(targetType, value));
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object getValue(PathInformation path, Class<?> targetType, Object value) {
|
||||
private Object getValue(TypeDescriptor targetType, Object value) {
|
||||
|
||||
if (ClassUtils.isAssignableValue(targetType, value)) {
|
||||
if (ClassUtils.isAssignableValue(targetType.getType(), value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (conversionService.canConvert(value.getClass(), targetType)) {
|
||||
return conversionService.convert(value, TypeDescriptor.forObject(value), getTargetTypeDescriptor(path));
|
||||
if (conversionService.canConvert(value.getClass(), targetType.getType())) {
|
||||
return conversionService.convert(value, TypeDescriptor.forObject(value), targetType);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assumptions.*;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
@@ -198,6 +199,18 @@ class QuerydslPredicateBuilderUnitTests {
|
||||
assertThat(predicate).isEqualTo(QUser.user.dateOfBirth.eq(format.parseDateTime(date).toDate()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesCommaSeparatedArgumentToListCorrectly() {
|
||||
|
||||
values.add("nickNames", "Walt,Heisenberg");
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
Constant<Object> constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(0);
|
||||
|
||||
assertThat(constant.getConstant()).isEqualTo(Arrays.asList("Walt", "Heisenberg"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-883
|
||||
void automaticallyInsertsAnyStepInCollectionReference() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user