Gson: @Expose vs @SerializedName

后端 未结 4 1739
无人及你
无人及你 2020-12-08 02:00

With respect to Gson what is the difference between @Expose and @SerializedName(\"stringValue\")?

4条回答
  •  情书的邮戳
    2020-12-08 02:31

    class Person{
    String name;
    String password;
    }
    

    suppose if i put i annotation Expose on top of a variable name or password without SerializedName, it will be serialized AS variable name

    But if we put SerializedName like ("username") or ("password"),they will be serialized with that key

    if Serialized

    {"username":"trinadh","password":"hello"}
    

    if not

    {"name":"trinadh","password":"hello"}
    

提交回复
热议问题