-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix parse private class error, for issue #3134
- Loading branch information
Showing
2 changed files
with
40 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
37 changes: 37 additions & 0 deletions
37
core/src/test/java/com/alibaba/fastjson2/issues_3100/Issue3134.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.fastjson2.issues_3100; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue3134 { | ||
@Test | ||
public void test() { | ||
String json = "{\"name\":\"希望小学\",\"students\":{\"age\":\"12\",\"id\":\"1\",\"name\":\"张宇\"}}"; | ||
School schoolOne = JSON.parseObject(json, School.class); | ||
JSONObject schoolTwo = JSON.parseObject(json); | ||
School schoolThree = schoolTwo.toJavaObject(School.class); | ||
JSONObject studentOne = schoolTwo.getJSONObject("students"); | ||
JSONArray studentTwo = schoolTwo.getJSONArray("students"); | ||
assertEquals("[{\"age\":\"12\",\"id\":\"1\",\"name\":\"张宇\"}]", studentTwo.toString()); | ||
} | ||
|
||
@Data | ||
private static class School{ | ||
private String name; | ||
private List<Student> students; | ||
} | ||
|
||
@Data | ||
private static class Student{ | ||
private String name; | ||
private String id; | ||
private String age; | ||
} | ||
} |