title: How to handle optional JSON fields in Retrofit for Android?
body: <p>I am working on a JSON parser for an Android application. When I call the server for data, there are some optional fields, how do I handle this in Retrofit using GSON converter?</p>
  
  <p>Normal response</p>
  
  <pre><code>{
     "status":"SUCCESS",
     "class-1":{
        "class.enddate":"Jan/10/2016",
        "class.startdate":"Jan/10/2015",
        "class.title":"Physics 1",
        "class.short.description":"Physics 1",
        "class.description":"This is a Physics Class"
     }
  }
  </code></pre>
  
  <p>Alternate response, when some fields do not have any data</p>
  
  <pre><code>{
    "status":"SUCCESS",
    "class-1":{
       "class.enddate":"Jan/10/2016",
       "class.startdate":"Jan/10/2015",
       "class.title":"Physics 1"
     }
  }
  </code></pre>
  
  <p><strong>POJO Classes</strong></p>
  
  <pre><code>public class MyClass {
      @Expose @SerializedName("status")
      public String status;
  
      @Expose @SerializedName("class-1")
      public MyClassInformation myClassInformation;
  }
  
  public class MyClassInformation {
      @Expose @SerializedName("class.title")
      public String classTitle;
  
      @Expose @SerializedName("class.short.description")
      public String classShortDescription;
  
      @Expose @SerializedName("class.description")
      public String classDescription;
  
      @Expose @SerializedName("class.startdate")
      public String startDate;
  
      @Expose @SerializedName("class.enddate")
      public String endDate;
  }
  </code></pre>
  
  <p>How do I create the POJO classes in a way to handle the optional fields not being present?
  At the moment the whole MyClassInformation object becomes NULL when fields become missing, Please help.</p>