Skip to content

Fix argument conversion in QuerydslPredicateBuilder. #2650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.0-GH-2649-SNAPSHOT</version>

<name>Spring Data Core</name>
<description>Core Spring concepts underpinning every Spring Data module.</description>
Expand Down Expand Up @@ -169,7 +169,7 @@
<version>${vavr}</version>
<optional>true</optional>
</dependency>

<!-- Eclipse Collections -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,29 @@ private Path<?> getPath(PathInformation path, QuerydslBindings bindings) {
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.test.util.ReflectionTestUtils.*;

import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.data.querydsl.Address;
import org.springframework.data.querydsl.QSpecialUser;
import org.springframework.data.querydsl.QUser;
Expand All @@ -31,7 +33,6 @@
import org.springframework.data.querydsl.User;
import org.springframework.data.querydsl.UserWrapper;
import org.springframework.data.querydsl.Users;
// import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.data.util.Version;
import org.springframework.format.support.DefaultFormattingConversionService;
Expand Down Expand Up @@ -181,6 +182,18 @@ void leavesCommaSeparatedArgumentUntouchedWhenTargetIsNotAnArray() {
assertThat(constant.getConstant()).isEqualTo("rivers,two");
}

@Test
void resolvesCommaSeparatedArgumentToListCorrectly() {

values.add("nickNames", "Walt,Heisenberg");

var predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);

var constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(0);

assertThat(constant.getConstant()).isEqualTo(Arrays.asList("Walt", "Heisenberg"));
}

@Test // DATACMNS-883
void automaticallyInsertsAnyStepInCollectionReference() {

Expand Down