-
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 zero or negative number key map deserialize, for issue #2570
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
core/src/test/java/com/alibaba/fastjson2/issues_2500/Issue2570.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,22 @@ | ||
package com.alibaba.fastjson2.issues_2500; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue2570 { | ||
@Test | ||
public void test() { | ||
String json = "{0:12,1:13,2:14,\"date\":\"2024-05-14\"}"; | ||
Map<Object, Object> map = JSON.parseObject(json, Map.class); | ||
|
||
Integer date0 = (Integer) map.get(0); | ||
assertNotNull(date0); | ||
|
||
Integer date1 = (Integer) map.get(1); | ||
assertNotNull(date1); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue2570.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,37 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue2570 { | ||
@Test | ||
public void test() { | ||
String json = "{0:12,1:13,2:14,\"date\":\"2024-05-14\"}"; | ||
Map<Object, Object> map = JSON.parseObject(json, Map.class); | ||
|
||
Integer date0 = (Integer) map.get(0); | ||
assertNotNull(date0); | ||
assertEquals(12, date0); | ||
|
||
Integer date1 = (Integer) map.get(1); | ||
assertNotNull(date1); | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
String json = "{-1:12,1:13,2:14,\"date\":\"2024-05-14\"}"; | ||
Map<Object, Object> map = JSON.parseObject(json, Map.class); | ||
|
||
Integer date0 = (Integer) map.get(-1); | ||
assertNotNull(date0); | ||
assertEquals(12, date0); | ||
|
||
Integer date1 = (Integer) map.get(1); | ||
assertNotNull(date1); | ||
} | ||
} |