Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

自定义Exception的class作为其他类成员时候反序列化属性丢失 #1500

@Dracula1984

Description

@Dracula1984
public class Aa extends Exception {

    public Aa(){
    }

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
public class C {

    private Exception e;

    public Exception getE() {
        return e;
    }

    public void setE(Exception e) {
        this.e = e;
    }

}
        Aa aa = new Aa();
        aa.setName("aa");
        C c = new C();
        c.setE(aa);
        String jsonC = JSON.toJSONString(c, SerializerFeature.WriteClassName);

        C c2 = JSON.parseObject(jsonC, C.class);
        System.out.println(c2.getE().getClass().getSimpleName());
        System.out.println(((Aa)c2.getE()).getName());

结果为
Aa null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions