spring-projects / spring-projects/spring-data-commons

QueryDSL web support: unable to customize Map properties [DATACMNS-1525]

Open
#1,921 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

type: bug
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

Geert Graat opened DATACMNS-1525 and commented

I am using QueryDSL web support and currently customizing it as per the documentation. I run into a problem with properties of type Map. Below is a snippet from my generated QITask class:

public final MapPath<String, String, StringPath> customFields = this.<String, String, StringPath>createMap("customFields", String.class, String.class, StringPath.class);

When I want to customize this property, I use the following

bindings.bind(task.customFields).first((path, values) -> ...

**

The problem is that because task.customFields is defined as a MapPath, the values parameter is inferred to be a Map. But when I run this, it always contains a List.

When I debugged the QuerydslPredicateBuilder.getPredicate(..) method, and the convertToPropertyPathSpecificType(..) method was called, I found that there is no Converter available in the default ConversionService in Spring to convert from String (which the query argument always is) and Map. Therefore the query arguments are simply returned in List. 

As a workaround, I registered my own Converter that splits the query argument string on a specific character and creates a Map with the first part as key and the second part as value. So with this, I can execute queries like:

http://...query?customFields=key:value

Affects: 2.1.6 (Lovelace SR6)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.