1

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.

Community
  • 1
  • 1
Anshul
  • 7,914
  • 12
  • 42
  • 65
  • why not check values for empty when you are getting them from you object.. or modify your gettter to return custom value when empty – Abhishek Singh Dec 18 '17 at 06:07
  • Check this [link](https://stackoverflow.com/questions/30216317/setting-default-value-to-a-variable-when-deserializing-using-gson) – yashkal Dec 18 '17 at 06:08

0 Answers0