title: Serialize/deserialize immutable objects that carry extra informations with Jackson
body: <p>I try to use only immutables objects in my application. I've got a REST service that will take arbitrary JSon objects as input. </p>
  
  <p>I've a Java class that map theses objects, and I want to make them immutable + able to deal with extra parameters (just like using <code>@JsonAnySetter</code>).</p>
  
  <p>Here is my java class:
  </p>
  
  <pre><code>public class Operation {
  
  private final String _id;
  
  private final String state;
  
  private final Map&lt;String, Object&gt; extra;
  
  public Operation(String _id, String state, Map&lt;String,Object&gt; extra) {
      this._id = _id;
      this.state = state;
      this.extra = extra;
  }
  
  // getters....
  }
  </code></pre>
  
  <p>Using <code>@JsonAnySetter</code> I would have:</p>
  
  <pre><code>public class Operation {
  
  private final String _id;
  
  private final String state;
  
  private Map&lt;String, Object&gt; extra = new HashMap&lt;&gt;();
  
  public Operation(String _id, String state) {
      this._id = _id;
      this.state = state;
  }
  
  @JsonAnySetter
  public void addExtra(String key, Object value) {
      this.extra.put(key,value);
  }
  
  // getters....
  }
  </code></pre>
  
  <p>But this is not immutable anymore !</p>
  
  <p>This will not work because Jackson do not find any "extra" json attribute to read. I would like that everything that cannot be mapped be added to my map.</p>
  
  <p>Any idea of how to do this ? (or is it just possible :)</p>
  
  <p>Note: I use javac with -parameters option and the <code>ParameterNameModule</code> from jackson so that I don't need <code>@JsonCreator</code> option.</p>