-
Couldn't load subscription status.
- Fork 38.8k
Closed as not planned
Closed as not planned
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issueA duplicate of another issue
Description
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 + '\'' +
'}';
}
}Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issueA duplicate of another issue