title: Specifying additional arguments to class creation when deserializing JSON
body: <p>Jackson has the handy feature that you can <a href="http://www.cowtowncoder.com/blog/archives/2009/07/entry_303.html" rel="nofollow">specify custom constructors or static factory methods to use when creating a class, getting parameters from the JSON object</a>.  However, I'm not sure what the best way is to pass an additional constructor argument to a deserialized object.  For example, I'd like to be able to have Jackson use this JSON to construct and initialize the following class:</p>
  
  <pre><code>{
      "x": "foo",
      "y": "bar",
      "z": "baz"
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class Foo {
      /*
       * conf and x &lt;b&gt;must&lt;/b&gt; be supplied at construction time
       */
      @JsonCreator
      public Foo(Configuration conf, @JsonValue("x") String x)
  
      public String getX();
  
      public String getY();
      public void setY(String y);
      public String getZ();
      public void setZ(String z);
  }
  
  public class SomeMainApplicationClass {
      public Foo loadFoo(InputStream in, Configuration conf) {
          ObjectMapper mapper = new ObjectMapper(/* ??? */);
          /* ??? */
          return mapper.readValue(in, Foo.class);
      }
  }
  </code></pre>
  
  <p>My first instinct was that I needed to create some sort of factory object:</p>
  
  <pre><code>public class FooFactory {
      private final Configuration conf;
      public FooFactory(Configuration conf) {
          this.conf = conf;
      }
      @JsonCreator
      public createFoo(@JsonProperty("x") String x) {
          return new Foo(conf, x);
      }
  }
  </code></pre>
  
  <p>But Jackson doesn't have a straightforward way to plug that in--most of the methods I've found (or annotation-based options) use static factory methods. </p>
  
  <p>The answer <strong>must not</strong> use global/static variables--I want to configure the Configuration object on a per-<a href="http://jackson.codehaus.org/1.8.1/javadoc/org/codehaus/jackson/map/ObjectMapper.html" rel="nofollow"><code>ObjectMapper</code></a> basis.</p>
  
  <p>My preferred answer <em>should</em>:</p>
  
  <ul>
  <li>Be brief! I know there are multiple ways to approach this, I'm looking for the simplest one</li>
  <li>Continue to leverage Jackson's ability to use reflection and interpret <a href="http://wiki.fasterxml.com/JacksonAnnotations" rel="nofollow">data-binding annotations</a> for the non-constructor properties, rather than writing a Deserializer that has to be updated every time I add or edit a settable property
  <ul>
  <li>Should not require me to manually read and buffer the object properties from JSON (i.e. don't duplicate BeanDeserializer._deserializeUsingPropertyBased)</li>
  </ul></li>
  <li>Work with <a href="http://wiki.fasterxml.com/JacksonMixInAnnotations" rel="nofollow">annotation mix-ins</a></li>
  </ul>
  
  <p>I've explored setting up custom <a href="http://jackson.codehaus.org/1.8.1/javadoc/org/codehaus/jackson/map/deser/CreatorContainer.html" rel="nofollow"><code>CreatorContainers</code></a> or <a href="http://jackson.codehaus.org/1.8.1/javadoc/org/codehaus/jackson/map/DeserializerProvider.html" rel="nofollow"><code>DeserializerProviders</code></a>, but I haven't come up with a method that meets my requirements yet.</p>