title: Create Json response of a particular Entity class using retrofit Android
body: <p>I have an Entity class and i want to create a json response which should be parsed by this entity class but i am not able to create exact json response and i get null while parsing json data . I cannot change entity so i want to create an exact matching json response.</p>
  
  <p>Entity Class</p>
  
  <pre><code> import com.googlecode.objectify.annotation.Entity;
   import com.googlecode.objectify.annotation.Id;
   import com.googlecode.objectify.annotation.Index;
  
   import java.util.Calendar;
   import java.util.UUID;
  
   @Entity
   public class Product {
  
  public enum Type {
      ALL, LEAFY, FRUITY
  }
  
  public enum Volume {
      WEIGHT("gms"), QUANTITY("pcs");
      private final String extension;
  
      Volume(String extension) {
          this.extension = extension;
      }
  
      public String getExtension() {
          return extension;
      }
  }
  
  @Id
  private String id;
  @Index
  private String name_english;
  private String name_hinglish;
  private int minimumVolume;
  private int maximumVolume;
  private int volumeSet; // Fruits can be purchased in 3, 6, 9, 12 quantity
  private String imageUrl;
  private int price;
  @Index
  private long time;
  @Index
  private Type type;
  @Index
  private Volume volume;
  
  public Product() {
  }
  
  public Product(String name_english, String name_hinglish, Type type, Volume volume, int price) {
      this.id = UUID.randomUUID().toString();
      this.name_english = name_english;
      this.name_hinglish = name_hinglish;
      this.type = type;
      this.volume = volume;
      this.price = price;
      this.maximumVolume = 0;
      this.minimumVolume = 0;
      this.volumeSet = 0;
      this.imageUrl = "";
      this.time = Calendar.getInstance().getTimeInMillis();
  }
  
  public int getPrice() {
      return price;
  }
  
  public long getTime() {
      return time;
  }
  
  public void setPrice(int price) {
      this.price = price;
  }
  
  public void setTime(long time) {
      this.time = time;
  }
  
  public void setId(String id) {
      this.id = id;
  }
  
  public void setName_english(String name_english) {
      this.name_english = name_english;
  }
  
  public void setName_hinglish(String name_hinglish) {
      this.name_hinglish = name_hinglish;
  }
  
  public void setType(Type type) {
      this.type = type;
  }
  
  public void setVolume(Volume volume) {
      this.volume = volume;
  }
  
  public void setMinimumVolume(int minimumVolume) {
      this.minimumVolume = minimumVolume;
  }
  
  public void setMaximumVolume(int maximumVolume) {
      this.maximumVolume = maximumVolume;
  }
  
  public void setImageUrl(String imageUrl) {
      this.imageUrl = imageUrl;
  }
  
  public String getImageUrl() {
      return imageUrl;
  }
  
  public int getMinimumVolume() {
      return minimumVolume;
  }
  
  public int getMaximumVolume() {
      return maximumVolume;
  }
  
  public void setVolumeSet(int volumeSet) {
      this.volumeSet = volumeSet;
  }
  
  public int getVolumeSet() {
      return volumeSet;
  }
  
  public String getId() {
      return id;
  }
  
  public String getName_english() {
      return (String.valueOf(name_english.charAt(0)).toUpperCase()
              .concat(name_english.substring(1).toLowerCase()));
  }
  
  public String getName_hinglish() {
      return name_hinglish;
  }
  
  public Type getType() {
      return type;
  }
  
  public Volume getVolume() {
      return volume;
  }
  
  public boolean isEmpty() {
      return (getId() == null || getId().isEmpty());
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Current json response</p>
  
  <pre><code>[{"id":1,"name_english":"Tomato","name_hinglish":"Tamatar","minimumVolume":10,"maximumVolume":20,"volumeSet":3,"imageUrl":"Tamatar","price":25,"time":"10:55","type":"ALL","volume":"gms"},{"id":1,"name_english":"Potato","name_hinglish":"Tamatar","minimumVolume":12,"maximumVolume":60,"volumeSet":12,"imageUrl":"Tamatar","price":25,"time":"10:55","type":"ALL","volume":"pcs"},{"id":1,"name_english":"Carrot","name_hinglish":"Tamatar","minimumVolume":10,"maximumVolume":20,"volumeSet":3,"imageUrl":"Tamatar","price":25,"time":"10:55","type":"ALL","volume":"pcs"}]
  </code></pre>
  
  <p>Retrofit Interface code</p>
  
  <pre><code> @GET("bhajipala.php")
   Call&lt;EntityList&lt;Product&gt;&gt; getProductInfoList();
  </code></pre>
  
  <p>Retrofit Code :</p>
  
  <pre><code>   private static final String BASE_URL = "http://139.59.77.124/Bhajipala/";
  private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
  
  private static Retrofit.Builder builder =
          new Retrofit.Builder()
                  .baseUrl(BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create());
  
  public static &lt;S&gt; S createService(Class&lt;S&gt; serviceClass) {
      Retrofit retrofit = builder.client(httpClient.build()).build();
      return retrofit.create(serviceClass);
  }
  </code></pre>
  
  <p>Response Parsing</p>
  
  <pre><code>      Response&lt;EntityList&lt;Product&gt;&gt; response = call.execute();
          if (response.body() != null &amp;&amp; response.body().getItems() != null) {
              // we get Items
              if (response.body().getItems().size() &gt; 0) {
                  // store to database
                  dbHandler.storeProducts(response.body().getItems());
                  broadcast(ACTION_SUCCESS);
              } else { // server sends empty list
                  Log.e(TAG, "Empty product list");
                  broadcast(ACTION_EMPTY);
              }
          } else {// bad response
              Log.e(TAG, "Bad response " + response.errorBody());
              broadcast(ACTION_ERROR);
          }
  </code></pre>