0

我正在使用 Gson,我想序列化并显示一个枚举。

我的枚举:

Tuple{

    SINGLE(1,"Single"), 
    DOUBLE(2,"Double")

    Tuple(int asInt,String properName){
        this.asInt=asInt;
        this.fullName=fullName;
    }

    public int AsInt;
    public String fullname;
}

我想要这样的输出:

(SINGLE:{asInt:1,fullName:'Single'},DOUBLE:{asInt:2,fullname:'Double'})

我该怎么做呢?

4

1 回答 1

2

如果我没记错的话,您似乎需要一些自定义序列化和反序列化。检查链接。它有一个非常自我描述的示例,您可以将其用作 kickstart。

于 2012-05-07T17:05:52.897 回答