springfilter
springfilter copied to clipboard
Support Search in ElementCollection
It would be nice if you could search for Elements in a collection.
Hey,
Just to give some news, I am going to change a few things as stated in #135 before going on with this issue, since @ElementCollection is basically a @OneToMany.
I also wanted to know what kind of search you want to do on those collections.
For example
collection in ('x', 'y', 'z'): is one ofx,y,zan element ofcollection?collection : 'x': isxinsidecollection?collection ! 'x': isxnot insidecollection?
I think that those are what you expect. Correct me if I am wrong please.
Hi im sorry it took me so long to Answer.
My thought was:
- Key exists
- Key exists with value
- Value exists
My use case would be for a map.
But your examples certainly do apply for Lists and in some part for maps to.
I will try to implement that sooner.
hi @torshid any update on this case?
Hey @wicaksono @moiflo033
Unfortunately I didn't get the time to focus on this issue. Your contributions are always welcome. You can also sponsor me so that I can give better support.
@torshid I think I have a solution for the parsing, but I don't know if that is enough.
I think this code in the class "StringConverter.java" at row 122 would be something to try out:
if (Map.class.isAssignableFrom(expectedType)) {
Map<String, String> hashMap = new HashMap<>();
String keyValues[] = input.split(",");
for (String keyValue : keyValues) {
String[] splitKeyValue = keyValue.split(":");
String key = splitKeyValue[0].trim();
String value = splitKeyValue[1].trim();
hashMap.put(key, value);
}
if (hashMap.isEmpty()) {
throw new ClassCastException("The input '" + input + "' could not be parsed to Map");
}
return hashMap;
}
Then you should be able to parse a string like this: 'Aashish:1, Bina:2, Chintu:3'
I cloned the repository and tried to build a jar to test it locally with mvn clean install but I get some error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-artifacts) on project spring-filter: Exit code: 2 -> [Help 1]
It is now possible to filter @ElementCollection (lists and maps) in version 3.0.0.
Consider map to be a Map<?, ?>, you can query: map.key : 'test' and map.value : 'test'.