Modify field value of POJO when constructed using GSON and Retrofit

时间:2017-12-18 05:57:45

标签: android retrofit2 gson

I am using the Retrofit (2.3.0) and I use the Retrofit-GSON-converter to create a POJO.

Let's say I have the following class:

public class Flight {
 @SerializedName("fromCity")
 private String fromCity;
 @SerializedName("toCity")
 private String toCity;
 @SerializedName("fromAirportName")
 private String fromAirportName;
 @SerializedName("toAirportName")
 private String toAirportName;

  // Getters + Setters
}

Now when I use a retrofit call to fetch the model, it parses without error and I get a List with all values set but sometimes I get an empty string for fromCity and toCity from my server.

What I want is to set the value of fromCity and toCity to custom values once the object is constructed such that I do not iterate over the List of the objects and update them individually.

0 个答案:

没有答案