-
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.
bug fix for toJavaObject, fix issue #728
- Loading branch information
Showing
4 changed files
with
55 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
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
46 changes: 46 additions & 0 deletions
46
core/src/test/java/com/alibaba/fastjson2/issues/Issue728.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,46 @@ | ||
package com.alibaba.fastjson2.issues; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue728 { | ||
@Test | ||
public void test() { | ||
String a = "{\"test\":\"123465\"}"; | ||
LinkedHashMap linkedHashMap = JSON.toJavaObject(a, LinkedHashMap.class); | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("data", linkedHashMap); | ||
Bean bean = jsonObject.toJavaObject(Bean.class); | ||
assertNotNull(bean.data); | ||
Object test = bean.data.get("test"); | ||
assertEquals("123465", test); | ||
} | ||
|
||
public static class Bean { | ||
public JSONObject data; | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
JSONObject jsonObject = new JSONObject(); | ||
ArrayList list = new ArrayList(); | ||
list.add("123465"); | ||
jsonObject.put("data", list); | ||
Bean1 bean = jsonObject.to(Bean1.class); | ||
ArrayList list1 = bean.data; | ||
assertEquals(1, list1.size()); | ||
assertEquals(list.get(0), list1.get(0)); | ||
} | ||
|
||
public static class Bean1 { | ||
public JSONArray data; | ||
} | ||
} |