Skip to content

Commit

Permalink
fix fastjson1 compatible parseArray not handling the resolve tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
rowstop authored and wenshao committed Mar 30, 2024
1 parent d2dcb5a commit 765d386
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,9 @@ public static <T> List<T> parseArray(String text, Class<T> type) {
text,
createReadContext(JSONFactory.getDefaultObjectReaderProvider(), DEFAULT_PARSER_FEATURE))
) {
return reader.read(paramType);
List<T> list = reader.read(paramType);
reader.handleResolveTasks(list);
return list;
} catch (com.alibaba.fastjson2.JSONException e) {
Throwable cause = e.getCause();
if (cause == null) {
Expand All @@ -2063,7 +2065,9 @@ public static <T> List<T> parseArray(String text, Class<T> clazz, ParserConfig c
text,
createReadContext(config.getProvider(), DEFAULT_PARSER_FEATURE))
) {
return reader.read(paramType);
List<T> list = reader.read(paramType);
reader.handleResolveTasks(list);
return list;
} catch (com.alibaba.fastjson2.JSONException e) {
Throwable cause = e.getCause();
if (cause == null) {
Expand All @@ -2083,7 +2087,9 @@ public static <T> List<T> parseArray(String text, Class<T> type, Feature... feat
text,
createReadContext(JSONFactory.getDefaultObjectReaderProvider(), DEFAULT_PARSER_FEATURE, features))
) {
return reader.read(paramType);
List<T> list = reader.read(paramType);
reader.handleResolveTasks(list);
return list;
} catch (com.alibaba.fastjson2.JSONException e) {
Throwable cause = e.getCause();
if (cause == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alibaba.fastjson2.issue_2300;

import com.alibaba.fastjson.JSONArray;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author 张治保
* @since 2024/3/29
*/
public class Issue2348 {
@Test
void test() {
ArrayList<Object> items = new ArrayList<>();
HashMap<Object, Object> item = new HashMap<>();
item.put("data", "data");
items.add(item);
items.add(item);
List<HashMap> newItems = JSONArray.parseArray(JSONArray.toJSONString(items), HashMap.class);
Assertions.assertEquals(items, newItems);
}
}

0 comments on commit 765d386

Please sign in to comment.