Skip to content

Commit

Permalink
add test for issue #1676
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 28, 2023
1 parent fc8364f commit d7c167d
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.alibaba.fastjson.v2issues;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

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

public class Issue1676 {
@Test
public void test() {
ParameterizedType parameterizedType = new ParameterizedType() {
@Override
public Type[] getActualTypeArguments() {
return new Type[] {Bean.class};
}

@Override
public Type getRawType() {
return Page.class;
}

@Override
public Type getOwnerType() {
return null;
}
};

String s = "{\"current\":1,\"hitCount\":false,\"optimizeCountSql\":true,\"orders\":[],\"pages\":1,\"records\":[{\"name\": \"test\"}],\"searchCount\":true,\"size\":10,\"total\":1}";
Page fastJson2PageObject = JSON.parseObject(s, parameterizedType);
assertSame(Bean.class, fastJson2PageObject.getRecords().get(0).getClass());
}

public static class Bean {
}

public static class Page<T> {
private List<T> records;

public List<T> getRecords() {
return records;
}

public void setRecords(List<T> records) {
this.records = records;
}
}
}

0 comments on commit d7c167d

Please sign in to comment.