问题描述
java中使用枚举时,如果涉及到restful调用,不可避免会涉及到枚举的序列化和反序列化工作;
如定义如下枚举
     public enum ResType {
     
    
INSTANCE(“虚拟机”, “INSTANCE”);
private String name;
private String type;
     ResType(String name, String type) {
     
    
this.name = name;
this.type = type;
}
     public String getName() {
     
    
return name;
}
     public void setName(String name) {
     
    
this.name = name;
}
     public String getType() {
     
    
return type;
}
     public void setType(String type) {
     
    
this.type = type;
}
}
上面代码默认的序列化结果为:
     {
     
    
“resType”: “INSTANCE”
}
如果我们期望序列化的结果为:
     {
     
    
     “resType”: {
     
    
“name”: “虚拟机”