Skip to content

Commit

Permalink
bug fix for none-asm deserialize FieldReaderList
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 9, 2024
1 parent 44d118c commit 4f9d999
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -34,7 +37,19 @@ void test() {

String jsonString = JSON.toJSONString(infos, JSONWriter.Feature.ReferenceDetection);
List<ClueListInfo> 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<ClueListInfo> clueListInfos1 = JSON.parseArray(jsonString, ClueListInfo.class);
assertSame(clueListInfos1.get(0).getContacts(), clueListInfos1.get(1).getContacts());
}

@Data
Expand Down

0 comments on commit 4f9d999

Please sign in to comment.