Java - Alias for Field Names

后端 未结 1 1775
终归单人心
终归单人心 2021-02-05 05:07

Say I have an Object:

Object A
    String field1 = \"abc\";
    String field2 = \"xyz\";

The json for the above is:

{
    \"Obj         


        
相关标签:
1条回答
  • 2021-02-05 05:33

    Use the annotation @SerializedName("name") on your fields. Like this:

    Object A
    @SerializedName("f1")
    String field1 = "abc";
    @SerializedName("f2")
    String field2 = "xyz";
    

    See https://google.github.io/gson/apidocs/com/google/gson/annotations/SerializedName.html.

    0 讨论(0)
提交回复
热议问题