@SerializedName and @Expose annotations

The @SerializedName annotation is needed for Gson to map the JSON keys with our fields. In keeping with Java's camelCase naming convention for class member properties, it is not recommended to use underscores to separate words in a variable. @SerializedName helps translate between the two.

@SerializedName("quota_remaining")
@Expose
private Integer quotaRemaining;


In the example above, we are telling Gson that our JSON key quota_remaining should be mapped to the Java field quotaRemaining.  If both of these values were the same, i.e. if our JSON key was quotaRemaining just like the Java field, then there would be no need for the @SerializedName annotation on the field because Gson would map them automatically.
The @Expose annotation indicates that this member should be exposed for JSON serialization or deserialization. 

Bu blogdaki popüler yayınlar

SDLC - Software Development Life Cycle