Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable naming support for setter/field for data binding from request headers #34062

Open
orcunbalcilar opened this issue Dec 10, 2024 · 1 comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@orcunbalcilar
Copy link

orcunbalcilar commented Dec 10, 2024

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 + '\'' +
      '}';
    }
  
  }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 10, 2024
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Dec 10, 2024
@bclozel
Copy link
Member

bclozel commented Dec 10, 2024

Related to #34039

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

4 participants