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时数据重复 #1986

Closed
msgdw opened this issue Nov 2, 2023 · 5 comments
Closed

[BUG] 反序列化List时数据重复 #1986

msgdw opened this issue Nov 2, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@msgdw
Copy link

msgdw commented Nov 2, 2023

问题描述

简要描述您碰到的问题。
当List泛型不为String时 反序列化会出现数据重复

环境信息

请填写以下信息:

  • OS信息: [e.g.:Windows 11]
  • JDK信息: [e.g.:Oraclejdk 21]
  • 版本信息:[e.g.:Fastjson2 2.0.41]

重现步骤

如何操作可以重现该问题:

package org.example;

import com.alibaba.fastjson2.JSON;
import lombok.Data;

import java.util.List;

public class Test {

    public static void main(String[] args) {
        Role adminRole = new Role("admin", "管理员");
        Role userRole = new Role("user", "用户");
        User user = new User("root", "123456", List.of(adminRole, userRole));

        String json = JSON.toJSONString(user);
        System.out.println(json);

        User newUser = JSON.parseObject(json, User.class);
        System.out.println(newUser);
    }

    @Data
    public static class User {
        private final String username;
        private final String password;
        private final List<Role> roles;
    }

    @Data
    public static class Role {
        private final String name;
        private final String description;
    }
}

打印的结果

{"password":"123456","roles":[{"description":"管理员","name":"admin"},{"description":"用户","name":"user"}],"username":"root"}
Test.User(username=root, password=123456, roles=[Test.Role(name=admin, description=管理员), Test.Role(name=user, description=用户), Test.Role(name=admin, description=管理员), Test.Role(name=user, description=用户)])

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。
{3862C2F0-FB1F-4769-9767-B9476D8C4626}

@msgdw msgdw added the bug Something isn't working label Nov 2, 2023
@wenshao
Copy link
Member

wenshao commented Nov 2, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.42-SNAPSHOT/
请帮忙用2.0.42-SNAPSHOT版本验证,正式版本预计在周末(11月5日)发布。

@msgdw
Copy link
Author

msgdw commented Nov 2, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.42-SNAPSHOT/ 请帮忙用2.0.42-SNAPSHOT版本验证,正式版本预计在周末(11月5日)发布。

BUG依旧存在 没有任何变化

@yanxutao89 yanxutao89 self-assigned this Nov 7, 2023
@yanxutao89
Copy link
Collaborator

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.42-SNAPSHOT/ 请帮忙用2.0.42-SNAPSHOT版本验证,正式版本预计在周末(11月5日)发布。

晚上我提PR处理

yanxutao89 added a commit to yanxutao89/fastjson2 that referenced this issue Nov 7, 2023
@wenshao
Copy link
Member

wenshao commented Nov 13, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.43-SNAPSHOT/
请帮忙用2.0.43-SNAPSHOT版本验证,正式版本预计在12月初发布。

@msgdw
Copy link
Author

msgdw commented Nov 30, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.43-SNAPSHOT/ 请帮忙用2.0.43-SNAPSHOT版本验证,正式版本预计在12月初发布。

没问题了

@msgdw msgdw closed this as completed Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants