crnk-framework icon indicating copy to clipboard operation
crnk-framework copied to clipboard

JsonProperty is not respected on filter

Open juanangel123 opened this issue 4 years ago • 3 comments

I have a resource with this getter:

@JsonProperty("isInWork")
public Boolean isInWork() {
    return {obtained from database}
}

But when I do this query

http://localhost:8080/api/my-resource?filter[isInWork]=true

And debug my API repository's findAll method, does not keep the property as is_in_work

image

What I did to overcome the situation by making a custom implementation of io.crnk.core.queryspec.internal.DefaultQueryPathResolver that sets the property mapJsonNames to false. That seems to fix the issue.

I have been debugging, and seems that this line is not correct:

https://github.com/crnk-project/crnk-framework/blob/master/crnk-core/src/main/java/io/crnk/core/queryspec/internal/DefaultQueryPathResolver.java#L91

It shouldn't be the other way around?

Thank you!

juanangel123 avatar Sep 10 '21 12:09 juanangel123

the line itself looks ok, not? if the source is json, it maps it tona java name.and vice versa. an issue with the caller?

remmeier avatar Sep 12 '21 11:09 remmeier

@remmeier Sorry maybe I didn't understand what does the code yet.

So then the mapJsonNames property in DefaultQueryPathResolver.java does convert the names from the query into Java names, but that affects the @JsonProperty annotation is not considered? If that's true then the code is ok, and I just didn't expect that behaviour.

Then it could be nice if that property is configurable, the same that it is allowUnknownAttributes.

juanangel123 avatar Sep 20 '21 16:09 juanangel123

if you like you can add a test case, notnsure yet where the problem is. it should respect the json property annoation everywhere and map accorgingly

remmeier avatar Sep 20 '21 20:09 remmeier