forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved fastjson 1.x compatible, for issues alibaba#1291
- Loading branch information
Showing
2 changed files
with
57 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
56 changes: 56 additions & 0 deletions
56
core/src/test/java/com/alibaba/fastjson2/issues_1000/Issue1291.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,56 @@ | ||
package com.alibaba.fastjson2.issues_1000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.TypeReference; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue1291 { | ||
@Test | ||
public void test() { | ||
String str = "{\"obj\":{\"unitCode\":\"755H\"}}"; | ||
Result<List> result = JSON.parseObject(str, new TypeReference<Result<List>>() {}); | ||
assertEquals(1, result.obj.size()); | ||
JSONObject object = (JSONObject) result.obj.get(0); | ||
assertNotNull(object); | ||
assertEquals("755H", object.get("unitCode")); | ||
} | ||
|
||
@Test | ||
public void test_1() { | ||
String info = "{\"obj\":{\"unitCode\":\"755H\"}}"; | ||
Result<List<String>> result = JSONObject.parseObject(info, new TypeReference<Result<List<String>>>() {}); | ||
assertEquals(1, result.obj.size()); | ||
String string = result.obj.get(0); | ||
assertEquals("{\"unitCode\":\"755H\"}", string); | ||
} | ||
|
||
@Test | ||
public void test_2() { | ||
String info = "{\"obj\":{\"unitCode\":\"755H\"}}"; | ||
Result<List<Info>> result = JSONObject.parseObject(info, new TypeReference<Result<List<Info>>>() {}); | ||
assertEquals(1, result.obj.size()); | ||
Info object = result.obj.get(0); | ||
assertNotNull(object); | ||
assertEquals("755H", object.unitCode); | ||
} | ||
|
||
public static class Result<T> { | ||
public Date date; | ||
public String errorCode; | ||
public String errorMessage; | ||
public T obj; | ||
public boolean success; | ||
} | ||
|
||
public static class Info{ | ||
public String unitCode; | ||
} | ||
|
||
} |