fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

List<String>反序列化时会生成双倍数据

Open monkey1993 opened this issue 2 years ago • 0 comments

版本:2.0.40 例如:[{"array":["test1", "test2", "test3"]}]序列化为Java对象,再反序列化为Json,就变成了[{"array":["test1","test2","test3","test1","test2","test3"]}]。元素数量变成双倍。代码如下:

public class JsonTest {

	static class ListTest {
		public final List<String> array;

		public ListTest(List<String> array) {
			this.array = array;
		}
	}

	@Test
	public void test() {
		String json = "[{\"array\":[\"test1\", \"test2\", \"test3\"]}]";
		List<ListTest> values = JSONObject.parseObject(json, TypeReference.collectionType(List.class, ListTest.class));
		System.out.println(JSONObject.toJSONString(values)); // [{"array":["test1","test2","test3","test1","test2","test3"]}]
	}
}

monkey1993 avatar Sep 17 '23 14:09 monkey1993