Skip to content

修复 WxMaExpressOrderInsured 保价字段被 final 固定导致无法配置的问题#4013

Merged
binarywang merged 3 commits into
developfrom
copilot/fix-insured-default-setting
May 20, 2026
Merged

修复 WxMaExpressOrderInsured 保价字段被 final 固定导致无法配置的问题#4013
binarywang merged 3 commits into
developfrom
copilot/fix-insured-default-setting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

问题核心是:WxMaExpressOrderInsured 中保价相关字段默认“不保价”且被 final 修饰,调用方无法按需切换为保价并设置金额。该改动让默认行为保持不变,同时恢复配置能力。

  • 变更:放开保价字段可配置性

    • 移除 useInsuredinsuredValuefinal 修饰,支持通过 setter / builder 修改。
    • 保留默认值语义:
      • useInsured 默认 INSURED_PROGRAM (0)
      • insuredValue 默认 DEFAULT_INSURED_VALUE (0)
    • useInsured 增加 @Builder.Default,确保 builder 场景下默认值一致。
  • 变更:补充针对性单元测试

    • 新增 WxMaExpressOrderInsuredTest,覆盖:
      • 无参构造默认值
      • setter 修改保价开关与金额
      • builder 自定义保价参数
      • JSON 序列化字段输出(use_insured / insured_value

示例(现在可显式配置保价):

WxMaExpressOrderInsured insured = WxMaExpressOrderInsured.builder()
  .useInsured(WxMaConstants.OrderAddInsured.USE_INSURED)
  .insuredValue(5000)
  .build();

Copilot AI changed the title [WIP] Fix default value for insurance setting in WxMaExpressOrderInsured 修复 WxMaExpressOrderInsured 保价字段被 final 固定导致无法配置的问题 May 19, 2026
Copilot AI requested a review from binarywang May 19, 2026 05:07
@binarywang binarywang marked this pull request as ready for review May 19, 2026 09:29
Copilot AI review requested due to automatic review settings May 19, 2026 09:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 修复了小程序快递下单请求对象 WxMaExpressOrderInsured 中保价字段因 final 导致调用方无法通过 setter/builder 配置的问题,在保持默认“不保价”语义不变的前提下,恢复了可配置能力,并补充了单元测试覆盖。

Changes:

  • 移除 useInsured / insuredValuefinal 修饰,允许通过 Lombok 生成的 setter 与 builder 进行配置。
  • useInsured 增加 @Builder.Default,保证 builder 场景下默认值与字段初始化保持一致。
  • 新增 WxMaExpressOrderInsuredTest,覆盖无参构造默认值、setter 修改、builder 自定义参数及序列化输出。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/express/request/WxMaExpressOrderInsured.java 放开保价字段可变性,并补齐 builder 默认值语义(@Builder.Default)。
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/express/request/WxMaExpressOrderInsuredTest.java 新增针对默认值、setter、builder 与 JSON 输出的单元测试用例。
Comments suppressed due to low confidence (1)

weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/express/request/WxMaExpressOrderInsuredTest.java:42

  • 这里的 JSON 断言用 json.contains(...) 依赖 Gson 的输出格式(是否有空格/是否开启 pretty printing 等),后续一旦序列化配置变化就可能误报失败。建议改为用 JsonParser.parseString(json) 解析成 JsonObject,再分别断言 use_insuredinsured_value 的数值。
    String json = WxMaGsonBuilder.create().toJson(insured);
    assertTrue(json.contains("\"use_insured\":1"));
    assertTrue(json.contains("\"insured_value\":5000"));

Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/efdcf29e-9406-4678-817a-d004ae6a5f17

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@binarywang binarywang merged commit b882c67 into develop May 20, 2026
1 check passed
@binarywang binarywang deleted the copilot/fix-insured-default-setting branch May 20, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

保价为何设置的默认不保价,并且是final ,无法修改

3 participants