You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.2 WebMVC查询参数数据绑定行为变更问题求助

Spring Boot 3.2.0升级后含@Builder的DTO查询参数绑定行为异常变更

将基于Spring Boot + Spring Web的REST API从3.1.6升级到3.2.0时,发现查询参数的数据绑定行为出现意外变更,部分场景引发错误或潜在bug。

复现示例

以下是包含嵌套对象DTO的REST控制器GET端点:

@RestController
@RequestMapping("/builder")
public class DemoLombokDataBuilder {

   @Data
   @Builder
   static class Dto {
      String field;
      Nested nested;
   }

   @Data
   static class Nested {
      String nestedField;
   }

   @GetMapping
   public String demo(Dto dto) {
      String result = dto.getField();

      if (dto.getNested() != null)
         result += dto.getNested().getNestedField();
      else
         result += ", nested is empty";

      return result;
   }
}

版本行为对比

Spring Boot 3.1.6 请求结果

URL结果
http://localhost:8080/builder?field=foofoo, nested is empty
http://localhost:8080/builder?field=foo&nested.nestedField=barfoobar

Spring Boot 3.2.0 请求结果

URL结果
http://localhost:8080/builder?field=foofoonull
http://localhost:8080/builder?field=foo&nested.nestedField=barfoobar

可见3.2版本会在未提供嵌套字段时实例化空值的嵌套对象,而非3.1版本的不实例化。若嵌套对象含@NotNull必填字段,还会触发HTTP 400错误,而3.1版本可正常处理。

触发条件验证

进一步测试发现,仅当DTO只能通过全参构造函数实例化时才会出现该问题。若使用无@Builder的DTO:

@Data
static class Dto {
   String field;
   Nested nested;
}

3.1和3.2版本结果一致:

URL结果
http://localhost:8080/builder?field=foofoo, nested is empty
http://localhost:8080/builder?field=foo&nested.nestedField=barfoobar

疑问

有没有其他开发者遇到类似问题?或是我们遗漏了文档或升级指南中的相关说明?目前我们认为这是可能引发潜在bug的行为变更问题。

内容的提问来源于stack exchange,提问作者Florian Patzl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:33:42