-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Fix incorrect @SerializedName annotations in WxMaXPayQueryOrderResponse.OrderInfo #3956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
2
commits into
develop
Choose a base branch
from
copilot/update-gson-serialized-name
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
...iapp/src/test/java/cn/binarywang/wx/miniapp/bean/xpay/WxMaXPayQueryOrderResponseTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package cn.binarywang.wx.miniapp.bean.xpay; | ||
|
|
||
| import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertNotNull; | ||
|
|
||
| /** | ||
| * 验证 {@link WxMaXPayQueryOrderResponse} GSON 反序列化正确性的单元测试。 | ||
| * | ||
| * <p>修复说明:{@link WxMaXPayQueryOrderResponse.OrderInfo} 中 {@code leftFee} 和 {@code wxOrderId} | ||
| * 字段的 {@code @SerializedName} 使用了驼峰命名({@code "leftFee"}、{@code "wxOrderId"}), | ||
| * 而微信小程序接口实际返回的 JSON key 为下划线分割形式({@code "left_fee"}、{@code "wx_order_id"}), | ||
| * 导致这两个字段无法正确反序列化。 | ||
| * | ||
| * @author GitHub Copilot | ||
| */ | ||
| public class WxMaXPayQueryOrderResponseTest { | ||
|
|
||
| private static final String JSON_WITH_SNAKE_CASE_KEYS = | ||
| "{" | ||
| + "\"errcode\":0," | ||
| + "\"errmsg\":\"ok\"," | ||
| + "\"order\":{" | ||
| + "\"order_id\":\"order123\"," | ||
| + "\"status\":1," | ||
| + "\"left_fee\":500," | ||
| + "\"wx_order_id\":\"wx_inner_order_456\"," | ||
| + "\"sett_state\":4" | ||
| + "}" | ||
| + "}"; | ||
|
|
||
| /** | ||
| * 验证 left_fee(下划线形式)能正确反序列化到 leftFee 字段。 | ||
| */ | ||
| @Test | ||
| public void testLeftFeeDeserializedFromSnakeCaseKey() { | ||
| WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create() | ||
| .fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class); | ||
|
|
||
| assertNotNull(response.getOrder(), "order 字段不应为 null"); | ||
| assertEquals(response.getOrder().getLeftFee(), Long.valueOf(500L), | ||
| "left_fee 应正确反序列化为 leftFee 字段"); | ||
| } | ||
|
|
||
| /** | ||
| * 验证 wx_order_id(下划线形式)能正确反序列化到 wxOrderId 字段。 | ||
| */ | ||
| @Test | ||
| public void testWxOrderIdDeserializedFromSnakeCaseKey() { | ||
| WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create() | ||
| .fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class); | ||
|
|
||
| assertNotNull(response.getOrder(), "order 字段不应为 null"); | ||
| assertEquals(response.getOrder().getWxOrderId(), "wx_inner_order_456", | ||
| "wx_order_id 应正确反序列化为 wxOrderId 字段"); | ||
| } | ||
|
|
||
| /** | ||
| * 验证 sett_state = 4(苹果iOS订单)能正确反序列化。 | ||
| */ | ||
| @Test | ||
| public void testSettStateAppleOrderValue() { | ||
| WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create() | ||
| .fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class); | ||
|
|
||
| assertNotNull(response.getOrder(), "order 字段不应为 null"); | ||
| assertEquals(response.getOrder().getSettState(), Integer.valueOf(4), | ||
| "sett_state = 4 表示苹果iOS订单,Apple公司结算中"); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类注释里写的是“GSON 反序列化”,项目中其余位置通常使用库名“Gson”(与 WxMaGsonBuilder 命名一致)。建议将这里的“GSON”改为“Gson”,避免专有名词大小写不一致。