Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] List<String>反序列化时会生成双倍数据 #1873

Closed
monkey1993 opened this issue Sep 17, 2023 · 1 comment
Closed

[BUG] List<String>反序列化时会生成双倍数据 #1873

monkey1993 opened this issue Sep 17, 2023 · 1 comment
Labels
bug Something isn't working fixed
Milestone

Comments

@monkey1993
Copy link

问题描述

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

环境信息

  • OS信息: Windows 11
  • JDK信息: Java 17
  • 版本信息:2.0.40

重现步骤

  1. 使用 test() 方法
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"]}]
	}
}

期待的正确结果

[{"array":["test1", "test2", "test3"]}]

相关日志输出

当前输出:[{"array":["test1","test2","test3","test1","test2","test3"]}]

附加信息

见代码。

@wenshao
Copy link
Member

wenshao commented Oct 6, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.41
问题已修复,请用新版本

@wenshao wenshao closed this as completed Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants