Spring webflux doesn't populate custom object from path variables with @ModelAttribute











up vote
1
down vote

favorite












I'm trying to adapt an application that works well with Spring MVC but that has a different behavior with Spring WebFlux



Here's my code with Spring Boot 5 - Spring MVC :



The controller :



@RestController
public class MyRestController {

@GetMapping("/test/{id}/{label}")
public ResponseEntity<Payload> test(@ModelAttribute Payload payload) {
return new ResponseEntity<>(payload,HttpStatus.OK);
}
}


The Payload object :



public class Payload {

@NotNull
private int id;

private String label;

public Payload() {}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}


My pom.xml



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>


I don't have written any custom converter, Spring populate my payload object automatically, everything is fine.



When I call :



http://localhost:8080/test/25/helloWorld


Response is



{"id":25,"label":"helloWorld"}


Then, I only change my pom.xml, switching from web to webflux :



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies>


And my Payload Object isn't populated anymore.



When I call :



http://localhost:8080/test/25/helloWorld


Response is



{"id":0,"label":null}


I know I could write a converter and register it with @ControllerAdvice, but I can't imagine that there isn't an automated solution to make it works again as it has always worked with Spring Web.



Does anyone already encountered the same problem as me ?



Thanks,



Julien










share|improve this question




























    up vote
    1
    down vote

    favorite












    I'm trying to adapt an application that works well with Spring MVC but that has a different behavior with Spring WebFlux



    Here's my code with Spring Boot 5 - Spring MVC :



    The controller :



    @RestController
    public class MyRestController {

    @GetMapping("/test/{id}/{label}")
    public ResponseEntity<Payload> test(@ModelAttribute Payload payload) {
    return new ResponseEntity<>(payload,HttpStatus.OK);
    }
    }


    The Payload object :



    public class Payload {

    @NotNull
    private int id;

    private String label;

    public Payload() {}

    public String getLabel() {
    return label;
    }

    public void setLabel(String label) {
    this.label = label;
    }

    public int getId() {
    return id;
    }

    public void setId(int id) {
    this.id = id;
    }
    }


    My pom.xml



    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    </dependencies>


    I don't have written any custom converter, Spring populate my payload object automatically, everything is fine.



    When I call :



    http://localhost:8080/test/25/helloWorld


    Response is



    {"id":25,"label":"helloWorld"}


    Then, I only change my pom.xml, switching from web to webflux :



    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    </dependencies>


    And my Payload Object isn't populated anymore.



    When I call :



    http://localhost:8080/test/25/helloWorld


    Response is



    {"id":0,"label":null}


    I know I could write a converter and register it with @ControllerAdvice, but I can't imagine that there isn't an automated solution to make it works again as it has always worked with Spring Web.



    Does anyone already encountered the same problem as me ?



    Thanks,



    Julien










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm trying to adapt an application that works well with Spring MVC but that has a different behavior with Spring WebFlux



      Here's my code with Spring Boot 5 - Spring MVC :



      The controller :



      @RestController
      public class MyRestController {

      @GetMapping("/test/{id}/{label}")
      public ResponseEntity<Payload> test(@ModelAttribute Payload payload) {
      return new ResponseEntity<>(payload,HttpStatus.OK);
      }
      }


      The Payload object :



      public class Payload {

      @NotNull
      private int id;

      private String label;

      public Payload() {}

      public String getLabel() {
      return label;
      }

      public void setLabel(String label) {
      this.label = label;
      }

      public int getId() {
      return id;
      }

      public void setId(int id) {
      this.id = id;
      }
      }


      My pom.xml



      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.0.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
      </parent>

      <dependencies>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      </dependencies>


      I don't have written any custom converter, Spring populate my payload object automatically, everything is fine.



      When I call :



      http://localhost:8080/test/25/helloWorld


      Response is



      {"id":25,"label":"helloWorld"}


      Then, I only change my pom.xml, switching from web to webflux :



      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.0.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
      </parent>

      <dependencies>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-webflux</artifactId>
      </dependency>
      </dependencies>


      And my Payload Object isn't populated anymore.



      When I call :



      http://localhost:8080/test/25/helloWorld


      Response is



      {"id":0,"label":null}


      I know I could write a converter and register it with @ControllerAdvice, but I can't imagine that there isn't an automated solution to make it works again as it has always worked with Spring Web.



      Does anyone already encountered the same problem as me ?



      Thanks,



      Julien










      share|improve this question















      I'm trying to adapt an application that works well with Spring MVC but that has a different behavior with Spring WebFlux



      Here's my code with Spring Boot 5 - Spring MVC :



      The controller :



      @RestController
      public class MyRestController {

      @GetMapping("/test/{id}/{label}")
      public ResponseEntity<Payload> test(@ModelAttribute Payload payload) {
      return new ResponseEntity<>(payload,HttpStatus.OK);
      }
      }


      The Payload object :



      public class Payload {

      @NotNull
      private int id;

      private String label;

      public Payload() {}

      public String getLabel() {
      return label;
      }

      public void setLabel(String label) {
      this.label = label;
      }

      public int getId() {
      return id;
      }

      public void setId(int id) {
      this.id = id;
      }
      }


      My pom.xml



      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.0.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
      </parent>

      <dependencies>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      </dependencies>


      I don't have written any custom converter, Spring populate my payload object automatically, everything is fine.



      When I call :



      http://localhost:8080/test/25/helloWorld


      Response is



      {"id":25,"label":"helloWorld"}


      Then, I only change my pom.xml, switching from web to webflux :



      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.0.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
      </parent>

      <dependencies>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-webflux</artifactId>
      </dependency>
      </dependencies>


      And my Payload Object isn't populated anymore.



      When I call :



      http://localhost:8080/test/25/helloWorld


      Response is



      {"id":0,"label":null}


      I know I could write a converter and register it with @ControllerAdvice, but I can't imagine that there isn't an automated solution to make it works again as it has always worked with Spring Web.



      Does anyone already encountered the same problem as me ?



      Thanks,



      Julien







      java spring spring-mvc spring-boot spring-webflux






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 22:43









      chrylis

      50k1678115




      50k1678115










      asked Nov 11 at 22:38









      Julien O

      7616




      7616
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          The Spring WebFlux reference documentation about @ModelAttribute does not mention URI path variables, unlike the same section in the reference documentation for Spring MVC:




          The Pet instance above is resolved as follows:




          • From the model if already added by using Model.

          • From the HTTP session by using @SessionAttributes.

          • From a URI path variable passed through a Converter (see the next
            example).

          • From the invocation of a default constructor.

          • From the invocation of a “primary constructor” with arguments that
            match to Servlet request parameters. Argument names are determined
            through JavaBeans @ConstructorProperties or through runtime-retained
            parameter names in the bytecode.




          At this point this is the expected behavior and there might be good reasons or limitations behind that choice. Feel free to open an enhancement request in Spring Framework for that.






          share|improve this answer





















          • Thanks Brian, I'll do that !
            – Julien O
            Nov 13 at 16:25











          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%2f53253955%2fspring-webflux-doesnt-populate-custom-object-from-path-variables-with-modelatt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          The Spring WebFlux reference documentation about @ModelAttribute does not mention URI path variables, unlike the same section in the reference documentation for Spring MVC:




          The Pet instance above is resolved as follows:




          • From the model if already added by using Model.

          • From the HTTP session by using @SessionAttributes.

          • From a URI path variable passed through a Converter (see the next
            example).

          • From the invocation of a default constructor.

          • From the invocation of a “primary constructor” with arguments that
            match to Servlet request parameters. Argument names are determined
            through JavaBeans @ConstructorProperties or through runtime-retained
            parameter names in the bytecode.




          At this point this is the expected behavior and there might be good reasons or limitations behind that choice. Feel free to open an enhancement request in Spring Framework for that.






          share|improve this answer





















          • Thanks Brian, I'll do that !
            – Julien O
            Nov 13 at 16:25















          up vote
          1
          down vote













          The Spring WebFlux reference documentation about @ModelAttribute does not mention URI path variables, unlike the same section in the reference documentation for Spring MVC:




          The Pet instance above is resolved as follows:




          • From the model if already added by using Model.

          • From the HTTP session by using @SessionAttributes.

          • From a URI path variable passed through a Converter (see the next
            example).

          • From the invocation of a default constructor.

          • From the invocation of a “primary constructor” with arguments that
            match to Servlet request parameters. Argument names are determined
            through JavaBeans @ConstructorProperties or through runtime-retained
            parameter names in the bytecode.




          At this point this is the expected behavior and there might be good reasons or limitations behind that choice. Feel free to open an enhancement request in Spring Framework for that.






          share|improve this answer





















          • Thanks Brian, I'll do that !
            – Julien O
            Nov 13 at 16:25













          up vote
          1
          down vote










          up vote
          1
          down vote









          The Spring WebFlux reference documentation about @ModelAttribute does not mention URI path variables, unlike the same section in the reference documentation for Spring MVC:




          The Pet instance above is resolved as follows:




          • From the model if already added by using Model.

          • From the HTTP session by using @SessionAttributes.

          • From a URI path variable passed through a Converter (see the next
            example).

          • From the invocation of a default constructor.

          • From the invocation of a “primary constructor” with arguments that
            match to Servlet request parameters. Argument names are determined
            through JavaBeans @ConstructorProperties or through runtime-retained
            parameter names in the bytecode.




          At this point this is the expected behavior and there might be good reasons or limitations behind that choice. Feel free to open an enhancement request in Spring Framework for that.






          share|improve this answer












          The Spring WebFlux reference documentation about @ModelAttribute does not mention URI path variables, unlike the same section in the reference documentation for Spring MVC:




          The Pet instance above is resolved as follows:




          • From the model if already added by using Model.

          • From the HTTP session by using @SessionAttributes.

          • From a URI path variable passed through a Converter (see the next
            example).

          • From the invocation of a default constructor.

          • From the invocation of a “primary constructor” with arguments that
            match to Servlet request parameters. Argument names are determined
            through JavaBeans @ConstructorProperties or through runtime-retained
            parameter names in the bytecode.




          At this point this is the expected behavior and there might be good reasons or limitations behind that choice. Feel free to open an enhancement request in Spring Framework for that.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 8:21









          Brian Clozel

          29.3k67098




          29.3k67098












          • Thanks Brian, I'll do that !
            – Julien O
            Nov 13 at 16:25


















          • Thanks Brian, I'll do that !
            – Julien O
            Nov 13 at 16:25
















          Thanks Brian, I'll do that !
          – Julien O
          Nov 13 at 16:25




          Thanks Brian, I'll do that !
          – Julien O
          Nov 13 at 16:25


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253955%2fspring-webflux-doesnt-populate-custom-object-from-path-variables-with-modelatt%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

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)