title: Gson optional and required fields
body: <p>How should one deal with <code>Gson</code>and required versus optional fields? </p>
  
  <p>Since all fields are optional, I can't really fail my network request based on if the response json contains some key, <code>Gson</code>will simply parse it to null.</p>
  
  <p>Method I am using <code>gson.fromJson(json, mClassOfT);</code></p>
  
  <p>For example if I have following json:</p>
  
  <pre><code>{"user_id":128591, "user_name":"TestUser"}
  </code></pre>
  
  <p>And my class:</p>
  
  <pre><code>public class User {
  
      @SerializedName("user_id")
      private String mId;
  
      @SerializedName("user_name")
      private String mName;
  
      public String getId() {
          return mId;
      }
  
      public void setId(String id) {
          mId = id;
      }
  
      public String getName() {
          return mName;
      }
  
      public void setName(String name) {
          mName = name;
      }
  }
  </code></pre>
  
  <p>Is the any option to get <code>Gson</code> to fail if json would not contain <code>user_id</code> or <code>user_name</code> key?</p>
  
  <p>There can be many cases where you might need at least some values to be parsed and other one could be optional?</p>
  
  <p>Is there any pattern or library to be used to handle this case globally?</p>
  
  <p>Thanks.</p>