How to serialize a JSON object child into a field?

前端 未结 6 840
一生所求
一生所求 2021-01-19 10:22

I have a JSON object that looks like this

{
  \"foo\":{
      \"bar\":\"bar\",
      \"echo\":\"echo\"
  }
}

But then my Java object looks

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-19 10:53

    Yes you can do this

    Add this import

    import com.google.gson.annotations.SerializedName;
    

    and declare the variable like this

     @SerializedName("echo")
      private String myCustomeName;
    

提交回复
热议问题