-
Notifications
You must be signed in to change notification settings - Fork 510
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
[FEATURE]org.bson.types.Decimal128转Double时会报错 #2558
Labels
enhancement
New feature or request
Milestone
Comments
@wenshao 温少, 假如上面优化的代码你看过没问题的话,我就提一个PR |
@ocean23 可以的,你提交吧 |
好的,我发PR |
ocean23
added a commit
to ocean23/fastjson2
that referenced
this issue
May 11, 2024
ocean23
added a commit
to ocean23/fastjson2
that referenced
this issue
May 11, 2024
Merged
@wenshao 温少,已发PR |
https://github.com/alibaba/fastjson2/releases/tag/2.0.50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
请描述您的需求或者改进建议
背景如下:
1、我们会把
java
对象通过fastjson
转为String
然后通过MQ 发送出来,在接收端会再通过fastjson
把String
转化JSONObject
2、由于fastjson缺省反序列化带小数点的数值类型为BigDecimal,所以上面
jsonData
这个JSONObject
里面的小数都会被转为BigDecimal
, 而由于我们的数据库用的是mongodb
,所以存储进mongodb
时这个BigDecimal
又会自动被转为org.bson.types.Decimal128
3、但是当我们从
MongoDB
读回这个JSONObject
对象时,由于java
映射这个JSONObject
的小数的类型是Double
,这时由于fastjson
代码里的ObjectReaderProvider.typeConverts
并没有把org.bson.types.Decimal128
转为Double
的Converts, 这时就会报can not cast to java.lang.Double, from class org.bson.types.Decimal128错误,以下是具体的代码:请描述你建议的实现方案
只要优化
TypeUtils.cast
这个方法,增加支持从org.bson.types.Decimal128
转为Double
就可以了,以下是具体的代码可能实现并不是最优美的方式,但是以下这个实现经过我的测试是可以解决我上面这个问题,在TypeUtils
类的1525行增加以下代码:The text was updated successfully, but these errors were encountered: