-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* compatible api support non-string key, for issue #3214
- Loading branch information
Showing
3 changed files
with
75 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
43 changes: 43 additions & 0 deletions
43
core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3214.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,43 @@ | ||
package com.alibaba.fastjson2.issues_3200; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONFactory; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue3214 { | ||
@Test | ||
public void test() { | ||
String json = "{\n" | ||
+ " \"k1\":{\n" | ||
+ " \"k2\":[\n" | ||
+ " {\n" | ||
+ " {} : {}\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " }\n" | ||
+ "}"; | ||
JSONObject jsonObject = JSON.parseObject(json); | ||
assertNotNull(jsonObject); | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
JSONReader.Context context = JSONFactory.createReadContext(); | ||
context.setObjectSupplier(() -> new com.alibaba.fastjson.JSONObject()); | ||
String json = "{\n" | ||
+ " \"k1\":{\n" | ||
+ " \"k2\":[\n" | ||
+ " {\n" | ||
+ " {} : {}\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " }\n" | ||
+ "}"; | ||
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) JSON.parse(json, context); | ||
assertNotNull(jsonObject); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3214.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,24 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue3214 { | ||
@Test | ||
public void test() { | ||
String json = "{\n" | ||
+ " \"k1\":{\n" | ||
+ " \"k2\":[\n" | ||
+ " {\n" | ||
+ " {} : {}\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " }\n" | ||
+ "}"; | ||
JSONObject jsonObject = JSON.parseObject(json); | ||
assertNotNull(jsonObject); | ||
} | ||
} |