Spring JPA QuerydslPredicate Snake Case











up vote
0
down vote

favorite












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.










share|improve this question




























    up vote
    0
    down vote

    favorite












    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.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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.










      share|improve this question















      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.







      spring-boot querydsl predicate






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 5:22

























      asked Nov 13 at 4:45









      Maz

      135312




      135312





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273966%2fspring-jpa-querydslpredicate-snake-case%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273966%2fspring-jpa-querydslpredicate-snake-case%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?