Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(GsonFactory): fix type Long covert to type Double #259

Merged
merged 5 commits into from
Oct 11, 2024

Conversation

TyroneMax
Copy link

说明

  1. 请确认你提交的PR是到 'develop' 分支,否则我会手动修改代码并关闭PR。
  2. 请确认没有更改代码风格(如tab缩进)
  3. 新特性添加请确认注释完备,如有必要,请在src/test/java下添加Junit测试用例

修改描述(包括说明bug修复或者添加新特性)

  1. [bug修复]
    controller中有使用到TableQuery类,其中Condition类的字段value为Object类,Gson在反序列化的时候会将Long类型转换成Double,导致查询失败。
image 具体原因是因为Object在反序列化的时候会使用到ObjectTypeAdapter,对于处理Number类默认会转换成Double类型 image 解决方案: image

xyz.erupt.core.config.GsonFactory添加如下代码,使用延迟解析策略(还有解析成Double或Long、BigDecimal策略)
.setObjectToNumberStrategy(ToNumberPolicy.LAZILY_PARSED_NUMBER)
其他策略看com.google.gson.ToNumberPolicy

@TyroneMax TyroneMax force-pushed the fix-gson-deserialize-number branch from 5883278 to 960fb33 Compare July 25, 2024 16:55
@erupts
Copy link
Owner

erupts commented Oct 11, 2024

非常简单有效的方法,由衷的感谢你对社区的贡献

@erupts erupts merged commit 093ac34 into erupts:develop Oct 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants