Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change @SerializedName, from GSON, of an attribute in a extended class

I have a class like this:

class A {
    @Expose
    @SerializedName("a_id")
    private String id;
}

Now I want to create class B that extends A, but, in B, I want to change the SerializedName of id to "b_id". Is there a way to do this?

like image 268
tpcordeiro Avatar asked Nov 03 '22 22:11

tpcordeiro


1 Answers

It isn't possible out of the box. You'll need to write a custom type adapter. See the Custom Serialization and Deserialization section of the Gson user's guide.

like image 129
Jesse Wilson Avatar answered Nov 09 '22 10:11

Jesse Wilson