You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have encountered an issue with Spring Boot's data binding mechanism. When using a class in a controller method to bind query parameters, a field named host automatically gets populated with the value from the HTTP Host header if no parameter named host is provided in the request.
This behavior is unexpected because the host field should remain null if the parameter is not present in the request. Instead, the field is populated with the host value from the incoming request, such as localhost:8080.
Steps to Reproduce
@Getter@Setter@NoArgsConstructor@AllArgsConstructorpublicclassInstancesFilterCriteria {
privateStringhost;
privateStringname;
// and many more
}
Expected Behavior
The host field should remain null when the parameter is not provided in the request.
Actual Behavior
The host field is automatically populated with the value of the HTTP Host header (localhost:8080), even though the parameter is not present in the request.
I recently migrated from Spring Boot 2.7.18 to 3.4.1, and this issue started occurring after the migration.
What I want to achieve is control over my parameter naming, as the current implementation is highly integrated into the API and changing the naming convention is difficult to conclude at this stage.
Is there a way to configure Spring Boot to handle such naming collisions differently or prevent this automatic binding to the HTTP Host header?
I would greatly appreciate at least a brief explanation of this behavior and potential solutions.
Best Regards,
Bartek
The text was updated successfully, but these errors were encountered:
Hi,
I have encountered an issue with Spring Boot's data binding mechanism. When using a class in a controller method to bind query parameters, a field named host automatically gets populated with the value from the HTTP Host header if no parameter named host is provided in the request.
This behavior is unexpected because the host field should remain null if the parameter is not present in the request. Instead, the field is populated with the host value from the incoming request, such as localhost:8080.
Steps to Reproduce
http call
GET /api/instances?name=MyServer
Expected Behavior
The host field should remain null when the parameter is not provided in the request.
Actual Behavior
The host field is automatically populated with the value of the HTTP Host header (localhost:8080), even though the parameter is not present in the request.
I recently migrated from Spring Boot 2.7.18 to 3.4.1, and this issue started occurring after the migration.
What I want to achieve is control over my parameter naming, as the current implementation is highly integrated into the API and changing the naming convention is difficult to conclude at this stage.
Is there a way to configure Spring Boot to handle such naming collisions differently or prevent this automatic binding to the HTTP Host header?
I would greatly appreciate at least a brief explanation of this behavior and potential solutions.
Best Regards,
Bartek
The text was updated successfully, but these errors were encountered: