forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix BigDecimal error,for issue alibaba#1831
- Loading branch information
1 parent
dfb3ff7
commit 506b930
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
core/src/test/java/com/alibaba/fastjson2/issues_1800/Issue1831.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,42 @@ | ||
package com.alibaba.fastjson2.issues_1800; | ||
|
||
import com.alibaba.fastjson2.JSONObject; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Serializable; | ||
import java.math.BigDecimal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class Issue1831 { | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
public static class TestCls | ||
implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private BigDecimal goodsWeight; | ||
private BigDecimal mineGrossWeight; | ||
private BigDecimal mineTareWeight; | ||
private BigDecimal mineWeighBridgeNet; | ||
private BigDecimal mineNetBeforeSapmle; | ||
private BigDecimal mineNetAfterSapmle; | ||
} | ||
@Test | ||
public void Test() { | ||
TestCls bean = new TestCls(); | ||
bean.setGoodsWeight(new BigDecimal("1.0009600000")); | ||
bean.setMineGrossWeight(new BigDecimal("1.0")); | ||
bean.setMineNetAfterSapmle(new BigDecimal("10.9600000")); | ||
bean.setMineNetBeforeSapmle(new BigDecimal("1.096")); | ||
bean.setMineWeighBridgeNet(new BigDecimal(".103")); | ||
String expected = "{\"goodsWeight\":1.0009600000,\"mineGrossWeight\":1.0," + | ||
"\"mineNetAfterSapmle\":10.9600000,\"mineNetBeforeSapmle\":1.096,\"" + | ||
"mineWeighBridgeNet\":0.103}"; | ||
assertEquals(expected, JSONObject.toJSONString(bean)); | ||
} | ||
} |