Skip to content

Commit

Permalink
bug fix for issue #2851
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 8, 2024
1 parent a2ecc31 commit 05edc92
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public static ObjectReader of(Type type, Class listClass, long features) {
instanceClass = TreeSet.class;
builder = (Function<NavigableSet, NavigableSet>) Collections::synchronizedNavigableSet;
break;
case "java.util.AbstractList$RandomAccessSubList":
instanceClass = ArrayList.class;
break;
default:
instanceClass = listClass;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.alibaba.fastjson2.issues_2800;

import com.alibaba.fastjson2.*;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2851 {
@Test
public void test() {
List<String> list = Arrays.asList("").subList(0, 1);
byte[] bytes = JSONB.toBytes(list, JSONWriter.Feature.WriteClassName);
JSONReader.AutoTypeBeforeHandler autoTypeFilter = JSONReader.autoTypeFilter("java.util.AbstractList");
JSONReader.Context context = JSONFactory.createReadContext();
context.config(autoTypeFilter);
List<String> parsed = (List<String>) JSONB.parse(bytes, context);
assertEquals(list.get(0), parsed.get(0));
}
}

0 comments on commit 05edc92

Please sign in to comment.