修复 WxMaExpressOrderInsured 保价字段被 final 固定导致无法配置的问题#4013
Merged
Conversation
Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/7b9ac09d-4355-480f-84b5-5c34c8bb6fb5 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix default value for insurance setting in WxMaExpressOrderInsured
修复 May 19, 2026
WxMaExpressOrderInsured 保价字段被 final 固定导致无法配置的问题
There was a problem hiding this comment.
Pull request overview
该 PR 修复了小程序快递下单请求对象 WxMaExpressOrderInsured 中保价字段因 final 导致调用方无法通过 setter/builder 配置的问题,在保持默认“不保价”语义不变的前提下,恢复了可配置能力,并补充了单元测试覆盖。
Changes:
- 移除
useInsured/insuredValue的final修饰,允许通过 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_insured和insured_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题核心是:
WxMaExpressOrderInsured中保价相关字段默认“不保价”且被final修饰,调用方无法按需切换为保价并设置金额。该改动让默认行为保持不变,同时恢复配置能力。变更:放开保价字段可配置性
useInsured与insuredValue的final修饰,支持通过 setter / builder 修改。useInsured默认INSURED_PROGRAM (0)insuredValue默认DEFAULT_INSURED_VALUE (0)useInsured增加@Builder.Default,确保 builder 场景下默认值一致。变更:补充针对性单元测试
WxMaExpressOrderInsuredTest,覆盖:use_insured/insured_value)示例(现在可显式配置保价):