alibaba / alibaba/fastjson2

toJSONString方法在序列化时会默认将float类型的值转换成bigdecimal类型,希望添加一个Feature枚举禁用这种行为

Open
#491 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 请描述您的需求或者改进建议
*对您想要需求或建议的清晰简洁的描述。*
在对于float类型的值进行toJSONString转换后,发现精度丢失了。后发现默认使用了BigDecimal来进行转化了,希望
添加一个枚举类来避免这种情况

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
`设置float money = 18888.64959f user.setMoney(money)
在经过toJSONStringf方法后 显示"money":18888.65`

Contributor guide

Open the contributing guide

Research direction

Start by locating the toJSONString entry point, the existing Feature enums, and the float-to-BigDecimal serialization path. Check related serialization tests first; done means the new feature option disables the conversion and a regression test preserves the requested float output without changing the default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.