Hi,

Data binding for request headers works from spring web 6.2.0 on. But setter method naming (so relatively field name) must match with request header name. This could lead to a bug easily if anyone changes the field name.

Could you support annotations on field/setter?

Request

POST http://localhost:8080/api/header
Content-Type: application/json
a: TEST
Content-Length: 198
User-Agent: IntelliJ HTTP Client/IntelliJ IDEA 2024.3.1
Accept-Encoding: br, deflate, gzip, x-gzip
Accept: */*

... (Request Body)

Actual

If we change the name to a different one than a, binding is not done because field name and header name must match.

Class binding is supported.

public class RequestHeadersClass {

          private String a; // if we change the name to a different one than 'a', binding is not done because field name and header name must match.

          public void setA(String a) {
              this.a = a;
          }

          @Override
          public String toString() {
              return "RequestHeadersClass{" +
                  "a='" + a + '\'' +
                  '}';
          }
      }

But record is not supported yet.

public record RequestHeaders(@RequestHeader String a) {}

Desired

  public class RequestHeadersClass {         

    @ParamName("a")
    private String <anything you want>;

    public void setA(String a) {
      this.a = a;
    }

    @Override
    public String toString() {
      return "RequestHeadersClass{" +
      "a='" + a + '\'' +
      '}';
    }

  }

Comment From: bclozel

Related to #34039

Comment From: bclozel

This is already supported with this: https://github.com/spring-projects/spring-framework/issues/34039#issuecomment-2532620111