Skip to content

Commit 765d386

Browse files
rowstopwenshao
authored andcommitted
fix fastjson1 compatible parseArray not handling the resolve tasks
1 parent d2dcb5a commit 765d386

File tree

2 files changed

+35
-3
lines changed
  • fastjson1-compatible/src

2 files changed

+35
-3
lines changed

fastjson1-compatible/src/main/java/com/alibaba/fastjson/JSON.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,9 @@ public static <T> List<T> parseArray(String text, Class<T> type) {
20382038
text,
20392039
createReadContext(JSONFactory.getDefaultObjectReaderProvider(), DEFAULT_PARSER_FEATURE))
20402040
) {
2041-
return reader.read(paramType);
2041+
List<T> list = reader.read(paramType);
2042+
reader.handleResolveTasks(list);
2043+
return list;
20422044
} catch (com.alibaba.fastjson2.JSONException e) {
20432045
Throwable cause = e.getCause();
20442046
if (cause == null) {
@@ -2063,7 +2065,9 @@ public static <T> List<T> parseArray(String text, Class<T> clazz, ParserConfig c
20632065
text,
20642066
createReadContext(config.getProvider(), DEFAULT_PARSER_FEATURE))
20652067
) {
2066-
return reader.read(paramType);
2068+
List<T> list = reader.read(paramType);
2069+
reader.handleResolveTasks(list);
2070+
return list;
20672071
} catch (com.alibaba.fastjson2.JSONException e) {
20682072
Throwable cause = e.getCause();
20692073
if (cause == null) {
@@ -2083,7 +2087,9 @@ public static <T> List<T> parseArray(String text, Class<T> type, Feature... feat
20832087
text,
20842088
createReadContext(JSONFactory.getDefaultObjectReaderProvider(), DEFAULT_PARSER_FEATURE, features))
20852089
) {
2086-
return reader.read(paramType);
2090+
List<T> list = reader.read(paramType);
2091+
reader.handleResolveTasks(list);
2092+
return list;
20872093
} catch (com.alibaba.fastjson2.JSONException e) {
20882094
Throwable cause = e.getCause();
20892095
if (cause == null) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.alibaba.fastjson2.issue_2300;
2+
3+
import com.alibaba.fastjson.JSONArray;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
11+
/**
12+
* @author 张治保
13+
* @since 2024/3/29
14+
*/
15+
public class Issue2348 {
16+
@Test
17+
void test() {
18+
ArrayList<Object> items = new ArrayList<>();
19+
HashMap<Object, Object> item = new HashMap<>();
20+
item.put("data", "data");
21+
items.add(item);
22+
items.add(item);
23+
List<HashMap> newItems = JSONArray.parseArray(JSONArray.toJSONString(items), HashMap.class);
24+
Assertions.assertEquals(items, newItems);
25+
}
26+
}

0 commit comments

Comments
 (0)