Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13433

Add @FormAttribute attributes to customize x-www-form-urlencoded

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: General Backlog
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      As requested on the Spring Boot issue tracker:
      https://github.com/spring-projects/spring-boot/issues/3890

      When processing an HttpRequest with x-www-form-urlencoded content, we can use a controller with POJO matching the payload structure.

      Example payload: value_first=value1&value_second=value2

      @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
       public String handlePost(@ModelAttribute Body body) {
       }
      

      POJO:

      public class Body {
       private String value_first;
       private String value_second;
      }
      

      The problem is that the variable names must match the field names in the HttpRequest payload in order to be processed by the controller. There is not way of naming them differently, for example, if I do not want to use underscores in Java variable and method names.

      What I would appreciate would be using something like this:

      @FormAttribute
      private String value1;
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rstoya05-aop Rossen Stoyanchev
                Reporter:
                pwebb Phil Webb
                Last updater:
                Zhang Jie
              • Votes:
                20 Vote for this issue
                Watchers:
                16 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since last comment:
                  28 weeks, 6 days ago