-
Notifications
You must be signed in to change notification settings - Fork 541
Closed
Labels
Milestone
Description
问题描述
@Test
public void testNumber() {
NumberTest test = new NumberTest();
test.setNum(10L);
test.setTime(new Date());
test.setDecimal(new BigDecimal("0.02"));
JSONObject jsonObject = (JSONObject) JSON.toJSON(test);
assert Long.class == jsonObject.get("num").getClass();
assert Date.class == jsonObject.get("time").getClass();
assert BigDecimal.class == jsonObject.get("decimal").getClass();
}
static class NumberTest {
private Long num;
private Date time;
private BigDecimal decimal;
public Long getNum() {
return num;
}
public void setNum(Long num) {
this.num = num;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public BigDecimal getDecimal() {
return decimal;
}
public void setDecimal(BigDecimal decimal) {
this.decimal = decimal;
}
}
环境信息
请填写以下信息:
- OS信息: [e.g.:MacOS / Windows]
- JDK信息: [e.g.:任意JDK版本]
- 版本信息:[e.g.:Fastjson2 2.0.49 / Fastjson(1.x兼容版) 2.0.49]
重现步骤
以上代码使用 Fastjson 1.2.83可以通过测试用例
使用Fastjson 2.0.49无法通过测试用例
经查是因为转换为JSONObject对象时,类型发生了变化