title: How to add setters using AutoValue extension in gson
body: <p>I recently came across the concept of using AutoValues (GSON) extension to speed up parsing our json data. We actuall found it parsed our json twice as fast.</p>
  
  <p>But I am missing a point, the data set while using AutoValues is immutable, but often our data sets/models are similar to the json and there are no mappers required. </p>
  
  <p>So if I want to set individual data elements in my model classes this does not look feasible(since we have only abstract getters and no setters. Is there a way around this problem or am I missing a point. 
  I will explain using a sample code of what we do and the similar syntax using AutoValue.</p>
  
  <p>So we usually write the code something like</p>
  
  <pre><code>public class ModelClass{
      private String aValue;
      private String anotherValue;
      public String getAValue(){
          return this.aValue;
      }
      public void setAValue(String aValue){
          this.aValue = aValue;
      }
      public String getAnotherValue(){
          return this.anotherValue;
      }
      public String setAnotherValue(anotherValue){
          this.anotherValue = anotherValue
      }
  }
  
  public class ViewClass{
       public void foo(){
            String json = {"aValue":"This is a sample string", "anotherValue": "this is another string"};
            ModelClass model = gson.fromJson(json, ModelClass.class);
            model.getAValue();
            model.setAValue("this is a new value"); // and we can set individual element ModelClass.aValue
  
  
       }
  }
  </code></pre>
  
  <p>But while using Auto Value the structure of the Model Class changes to </p>
  
  <pre><code>  @AutoValue public abstract class AutoValueModel{
         public abstract String bValue();
         public abstract String otherValue();
  
         public static AutoValueModel(String bValue, String otherValue){
             return new AutoValue_AutoValueModel(bValue, otherValue);
         }
    }
  </code></pre>
  
  <p>// Now as you can see AutoValueModel structure does not contain any setters what if I may want to change just the bValue (based on say a user action, even though I know that the basic premise behind AutoValues is them being immutable) and continue using in other parts of code. And then serialize a json using the very same AutoValueModel. 
  Or should I deserialize using AutoValue technique and then use a mapped model on which I can perform changes to the dataset? (Will I lose the benefit of speed attained by using AutoValue if I use this technique?)</p>
  
  <p>Also reference from where I learnt about AutoValues :</p>
  
  <p><a href="http://ryanharter.com/blog/2016/03/22/autovalue/" rel="nofollow">An Introduction to AutoValue</a></p>
  
  <p><a href="http://dubedout.eu/2016/07/11/faster-json-deserialization-autovalue-extension/" rel="nofollow">FASTER JSON DESERIALIZATION WITH AUTOVALUE GSON EXTENSION</a></p>