From 4f9d9995841d5e283fdf05e1d56b0287a3ef514e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=93=81?= Date: Sun, 7 Jul 2024 17:48:46 +0800 Subject: [PATCH] bug fix for none-asm deserialize FieldReaderList --- .../fastjson2/reader/FieldReaderList.java | 11 +++++++++++ .../fastjson2/issues_2700/Issue2712.java | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderList.java b/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderList.java index 11e06ba319..04c8d99800 100644 --- a/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderList.java +++ b/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderList.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson2.JSONB; import com.alibaba.fastjson2.JSONException; +import com.alibaba.fastjson2.JSONPath; import com.alibaba.fastjson2.JSONReader; import com.alibaba.fastjson2.schema.JSONSchema; import com.alibaba.fastjson2.util.Fnv; @@ -73,6 +74,16 @@ public void readFieldValue(JSONReader jsonReader, T object) { return; } + if (jsonReader.isReference()) { + String reference = jsonReader.readReference(); + if ("..".equals(reference)) { + accept(object, object); + } else { + addResolveTask(jsonReader, object, reference); + } + return; + } + JSONReader.Context context = jsonReader.getContext(); ObjectReader objectReader = getObjectReader(context); diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_2700/Issue2712.java b/core/src/test/java/com/alibaba/fastjson2/issues_2700/Issue2712.java index 7f93338eae..70453fbac7 100644 --- a/core/src/test/java/com/alibaba/fastjson2/issues_2700/Issue2712.java +++ b/core/src/test/java/com/alibaba/fastjson2/issues_2700/Issue2712.java @@ -2,6 +2,9 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONWriter; +import com.alibaba.fastjson2.reader.ObjectReaderCreator; +import com.alibaba.fastjson2.writer.ObjectWriter; +import com.alibaba.fastjson2.writer.ObjectWriterCreator; import com.google.common.collect.Lists; import lombok.Data; import org.junit.jupiter.api.Test; @@ -10,7 +13,7 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class Issue2712 { @Test @@ -34,7 +37,19 @@ void test() { String jsonString = JSON.toJSONString(infos, JSONWriter.Feature.ReferenceDetection); List clueListInfos = JSON.parseArray(jsonString, ClueListInfo.class); - assertEquals(clueListInfos.get(0).getContacts(), clueListInfos.get(1).getContacts()); + assertSame(clueListInfos.get(0).getContacts(), clueListInfos.get(1).getContacts()); + + assertNotNull(JSON.register(ClueListInfo.class, + ObjectWriterCreator.INSTANCE.createObjectWriter(ClueListInfo.class))); + + assertEquals(jsonString, + JSON.toJSONString(infos, JSONWriter.Feature.ReferenceDetection)); + + assertNotNull(JSON.register(ClueListInfo.class, + ObjectReaderCreator.INSTANCE.createObjectReader(ClueListInfo.class))); + + List clueListInfos1 = JSON.parseArray(jsonString, ClueListInfo.class); + assertSame(clueListInfos1.get(0).getContacts(), clueListInfos1.get(1).getContacts()); } @Data