问题
I am using spring boot with Query DSL. I have configured my spring boot to use snake case i.e. spring.jackson.property-naming-strategy=SNAKE_CASE
. So my json payload input and output is in snake case like below
{
"first_name": "First",
"last_name": "Last"
}
I am using @QuerydslPredicate
for my search functionality. If I enter query params in snake case like below
(http://localhost:8080/context/resource/?first_name=First)
it is not parsed by Query DSL Predicate. However, If I provide the params in camel case like below
(http://localhost:8080/context/resource/?firsName=First)
it works fine. This is not synonymous with json structure.
How can I achieve snake case in query params so that Query DSL parses it?
This is how my REST end point looks like
@GetMapping
public ResponseEntity<Output> listUsers(@QuerydslPredicate(root = User.class) Predicate predicate, Pageable pageable) {
...
return new ResponseEntity<>(output, HttpStatus.OK);
}
PN: My Model Object is in camel case like below
Model Object
public class User {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
I came across a solution on HandlerMethodArgumentResolver, but that is lot of work. There should be a way to automate it than doing all model fields.
来源:https://stackoverflow.com/questions/53273966/spring-jpa-querydslpredicate-snake-case