Skip to content
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

JSON.parseArray丢失Long的精度 #97

Closed
wsxe9988 opened this issue Apr 27, 2022 · 4 comments
Closed

JSON.parseArray丢失Long的精度 #97

wsxe9988 opened this issue Apr 27, 2022 · 4 comments

Comments

@wsxe9988
Copy link
Contributor

下面是实体类

@DaTa
@slf4j
public class LiveWaterVO implements Serializable {

private String name;

private Long level1;

private Long level2;

private Long level3;

private Long wl;

@JsonIgnoreProperties(ignoreUnknown = true)
private Long wlSixHoursAgo;

@JsonIgnoreProperties(ignoreUnknown = true)
private Long wlThreeHoursAgo;

@JsonIgnoreProperties(ignoreUnknown = true)
private Long wlOneHourAgo;
}
原来的JSON:

[{"wl":0.01,"name":"西桥","level1":"9","level3":"0.7","level2":"1.4"}]
进行下面的转换后:

List liveWaterVOS = JSON.parseArray(jsonArrayStr,LiveWaterVO.class);
System.out.println(liveWaterVOS);
结果显示如下:
[LiveWaterVO(name=西桥, level1=9, level2=1, level3=0, wl=0, wlSixHoursAgo=null, wlThreeHoursAgo=null, wlOneHourAgo=null)]

ref alibaba/fastjson#4038

@wenshao
Copy link
Member

wenshao commented Apr 27, 2022

这个有什么问题?

@wsxe9988
Copy link
Contributor Author

原始json串中 wl值为0.01 parseArray 输出变成0;level3值为0.7 parseArray 输出变成0;level2值为1.4 parseArray 输出变成1,,精度缺失了

@wenshao
Copy link
Member

wenshao commented Apr 28, 2022

对象类型就是Long,按这个输入,就应该是截断吧

@wsxe9988
Copy link
Contributor Author

确实是,Long是长整型,会截断,Double就不会丢失精度了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants