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

Set类型集合无法正常反序列化 #555

Closed
1455668754 opened this issue Jul 13, 2022 · 6 comments
Closed

Set类型集合无法正常反序列化 #555

1455668754 opened this issue Jul 13, 2022 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@1455668754
Copy link

问题描述

对象中存在Set类型集合时,序列化时会添加Set标识,但无法正常反序列化获取到数据
image
image
image
(实测:手动移除掉Set标识后,可正常反序列化)

版本: 在>2.0.4版本均存在该问题(包括最新发布的2.0.9版本)

@1455668754 1455668754 added the bug Something isn't working label Jul 13, 2022
@1455668754 1455668754 changed the title [BUG] Set类型集合无法正常反序列化 Jul 13, 2022
@wsxe9988
Copy link
Contributor

麻烦提供下完整的case,以供复现

@wenshao wenshao added this to the 2.0.10 milestone Jul 13, 2022
wenshao added a commit that referenced this issue Jul 13, 2022
@wenshao
Copy link
Member

wenshao commented Jul 13, 2022

问题没重现,需要帮助提供重现问题的testcase

@1455668754
Copy link
Author

1455668754 commented Jul 14, 2022

import com.alibaba.fastjson2.JSON;
import java.util.Set;

public class Test {

public static void main(String[] args)  {
    // 可正常序列化 (无Set)
    String ss1 =  "{\"@type\":\"com.xueyi.system.api.model.LoginUser\",\"enterpriseId\":1,\"enterpriseName\":\"administrator\",\"expireTime\":1657824093068,\"ipaddr\":\"127.0.0.1\",\"isLessor\":\"Y\",\"loginTime\":1657780893068,\"permissions\":[\"*:*:*\"],\"roleIds\": [],\"roles\":[\"administrator\",\"admin\"],\"scope\":{\"dataScope\":\"1\",\"deptScope\":[],\"postScope\":[],\"userScope\":[]},\"sourceName\":\"slave\",\"token\":\"d9d04f73-6933-47b5-8549-963733b96ddf\",\"userId\":1,\"userName\":\"admin\",\"userType\":\"00\"}";
    // 反序列化异常 (有Set)
    String ss2 =  "{\"@type\":\"com.xueyi.system.api.model.LoginUser\",\"enterpriseId\":1,\"enterpriseName\":\"administrator\",\"expireTime\":1657824093068,\"ipaddr\":\"127.0.0.1\",\"isLessor\":\"Y\",\"loginTime\":1657780893068,\"permissions\":Set[\"*:*:*\"],\"roleIds\": Set[],\"roles\":Set[\"administrator\",\"admin\"],\"scope\":{\"dataScope\":\"1\",\"deptScope\":Set[],\"postScope\":Set[],\"userScope\":Set[]},\"sourceName\":\"slave\",\"token\":\"d9d04f73-6933-47b5-8549-963733b96ddf\",\"userId\":1,\"userName\":\"admin\",\"userType\":\"00\"}";

    LoginUser bean1 = JSON.parseObject(ss1, LoginUser.class);
    System.out.println(bean1);
    LoginUser bean2 = JSON.parseObject(ss2, LoginUser.class);
    System.out.println(bean2);
}

public static class LoginUser {

    private static final long serialVersionUID = 1L;

    /** 用户唯一标识 */
    private String token;

    /** 企业账号Id */
    private Long enterpriseId;

    /** 企业账号 */
    private String enterpriseName;

    /** 租户标识 */
    private String isLessor;

    /** 用户名Id */
    private Long userId;

    /** 用户名 */
    private String userName;

    /** 用户标识 */
    private String userType;

    /** 主数据源 */
    private String sourceName;

    /** 登录时间 */
    private Long loginTime;

    /** 过期时间 */
    private Long expireTime;

    /** 登录IP地址 */
    private String ipaddr;

    /** 权限列表 */
    private Set<String> permissions;

    /** 角色权限列表 */
    private Set<String> roles;

    /** 角色Id列表 */
    private Set<Long> roleIds;

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(Long enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getEnterpriseName() {
        return enterpriseName;
    }

    public void setEnterpriseName(String enterpriseName) {
        this.enterpriseName = enterpriseName;
    }

    public String getIsLessor() {
        return isLessor;
    }

    public void setIsLessor(String isLessor) {
        this.isLessor = isLessor;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public Long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Long expireTime) {
        this.expireTime = expireTime;
    }

    public String getIpaddr() {
        return ipaddr;
    }

    public void setIpaddr(String ipaddr) {
        this.ipaddr = ipaddr;
    }

    public Set<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(Set<String> permissions) {
        this.permissions = permissions;
    }

    public Set<String> getRoles() {
        return roles;
    }

    public void setRoles(Set<String> roles) {
        this.roles = roles;
    }

    public Set<Long> getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(Set<Long> roleIds) {
        this.roleIds = roleIds;
    }

}

}

@1455668754
Copy link
Author

可以直接拿这整段测试(不好意思,没找到怎么上传文件),简单的Set集合对象是可以转换的,但是在复杂对象中,无法正常转换,demo中我测试了两个情况,前者是有Set标识,无法正常转换,后者无Set标识,可以正常转换(注释掉的ss字符串)

@wenshao
Copy link
Member

wenshao commented Jul 14, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.10-SNAPSHOT/
问题已经修复,请用2.0.10-SNAPSHOT版本验证,2.0.10预计在7月24日前发布

@wenshao
Copy link
Member

wenshao commented Jul 23, 2022

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

@wenshao wenshao closed this as completed Jul 23, 2022
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