-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix adjust readNumber0 for decimal with suffix of B,S or L, for issue #…
- Loading branch information
1 parent
e8a1910
commit 261688f
Showing
3 changed files
with
47 additions
and
6 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
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
41 changes: 41 additions & 0 deletions
41
core/src/test/java/com/alibaba/fastjson2/issues_2700/Issue2769.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,41 @@ | ||
package com.alibaba.fastjson2.issues_2700; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2769 { | ||
@Test | ||
public void testWithSuffixB() { | ||
String str = "{\"k1\":123.456,\"k2\":12.34B}"; | ||
test(JSON.parseObject(str)); | ||
test(JSON.parseObject(str.getBytes(StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testWithSuffixS() { | ||
String str = "{\"k1\":123.456,\"k2\":12.34S}"; | ||
test(JSON.parseObject(str)); | ||
test(JSON.parseObject(str.getBytes(StandardCharsets.UTF_8))); | ||
} | ||
|
||
@Test | ||
public void testWithSuffixL() { | ||
String str = "{\"k1\":123.456,\"k2\":12.34L}"; | ||
test(JSON.parseObject(str)); | ||
test(JSON.parseObject(str.getBytes(StandardCharsets.UTF_8))); | ||
} | ||
|
||
private void test(JSONObject jsonObject) { | ||
assertEquals((byte) 12, jsonObject.getByte("k2")); | ||
assertEquals((short) 12, jsonObject.getShort("k2")); | ||
assertEquals(12, jsonObject.getInteger("k2")); | ||
assertEquals(12, jsonObject.getLong("k2")); | ||
assertEquals(12.34F, jsonObject.getFloat("k2")); | ||
assertEquals(12.34, jsonObject.getDouble("k2")); | ||
} | ||
} |