簡體   English   中英

使用Gson顯示枚舉的地圖及其屬性

[英]Using Gson to display map of enums with their properties

我正在使用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'})

我該怎么做呢?

如果我沒有弄錯,似乎你需要一些自定義序列化和反序列化。 檢查鏈接。 它有一個非常自我描述的例子,你可以用作kickstart。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM