[WIP] Fix GsonParser parse error during transfer#3760
Merged
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
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.
修复 GsonParser 与低版本 Gson 的兼容性问题
问题描述
用户在使用商家转账接口时,遇到
NoSuchMethodError: JsonParser.parseString()错误。这是因为JsonParser.parseString()方法在 Gson 2.8.6 之前的版本中不存在。虽然项目定义了 Gson 2.13.1,但用户运行时可能因为依赖冲突而使用了更低版本的 Gson。修复计划
技术细节
问题原因:
JsonParser.parseString()和JsonParser.parseReader()是 Gson 2.8.6 新增的静态方法NoSuchMethodError修改内容:
JsonParser.parseString(json)改为new JsonParser().parse(json)JsonParser.parseReader(json)改为new JsonParser().parse(json)兼容性说明:
new JsonParser().parse()方法在 Gson 2.1+ 版本中都可用,兼容性更好new JsonParser()在 Gson 2.8.6+ 中被标记为 deprecated,但为了向后兼容性,这是必要的权衡验证结果:
安全总结
未发现安全漏洞。此次修改仅是将 Gson API 调用改为更兼容的版本,不涉及任何安全相关的逻辑变更。
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.