-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix 1.x compatible api JSON#toJSON, for issue #2447
- Loading branch information
Showing
3 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
core/src/test/java/com/alibaba/fastjson2/issues_2400/Issue2447.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.alibaba.fastjson2.issues_2400; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Date; | ||
|
||
public class Issue2447 { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.setNum(10L); | ||
bean.setTime(new Date()); | ||
bean.setDecimal(new BigDecimal("0.02")); | ||
JSONObject jsonObject = (JSONObject) JSON.toJSON(bean); | ||
assert Long.class == jsonObject.get("num").getClass(); | ||
assert Date.class == jsonObject.get("time").getClass(); | ||
assert BigDecimal.class == jsonObject.get("decimal").getClass(); | ||
} | ||
|
||
static class Bean { | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue2447.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Date; | ||
|
||
public class Issue2447 { | ||
@Test | ||
public void test() { | ||
Bean bean = new Bean(); | ||
bean.setNum(10L); | ||
bean.setTime(new Date()); | ||
bean.setDecimal(new BigDecimal("0.02")); | ||
JSONObject jsonObject = (JSONObject) JSON.toJSON(bean); | ||
assert Long.class == jsonObject.get("num").getClass(); | ||
assert Date.class == jsonObject.get("time").getClass(); | ||
assert BigDecimal.class == jsonObject.get("decimal").getClass(); | ||
} | ||
|
||
static class Bean { | ||
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; | ||
} | ||
} | ||
} |