title: Jackson, deserialize class with private fields and arg-constructor without annotations
body: <p>It is possible to deserialize to a class with private fields and a custom argument constructor without using annotations and without modifying the class, using Jackson?</p>
  <p>I know it's possible in Jackson when using this combination: 1) Java 8, 2) compile with &quot;-parameters&quot; option, and 3) the parameters names match JSON. But it's also possible in GSON by default without all these restrictions.</p>
  <p>For example:</p>
  <pre><code>public class Person {
      private final String firstName;
      private final String lastName;
      private final int age;
  
      public Person(String firstName, String lastName, int age) {
          this.firstName = firstName;
          this.lastName = lastName;
          this.age = age;
      }
  
      public static void main(String[] args) throws IOException {
          String json = &quot;{firstName: \&quot;Foo\&quot;, lastName: \&quot;Bar\&quot;, age: 30}&quot;;
          
          System.out.println(&quot;GSON: &quot; + deserializeGson(json)); // works fine
          System.out.println(&quot;Jackson: &quot; + deserializeJackson(json)); // error
      }
  
      public static Person deserializeJackson(String json) throws IOException {
          ObjectMapper mapper = new ObjectMapper();
          mapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
          mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
          return mapper.readValue(json, Person.class);
      }
  
      public static Person deserializeGson(String json) {
          Gson gson = new GsonBuilder().create();
          return gson.fromJson(json, Person.class);
      }
  }
  </code></pre>
  <p>Which works fine for GSON, but Jackson throws:</p>
  <pre><code>Exception in thread &quot;main&quot; com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `jacksonParametersTest.Person` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
   at [Source: (String)&quot;{firstName: &quot;Foo&quot;, lastName: &quot;Bar&quot;, age: 30}&quot;; line: 1, column: 2]
      at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
  </code></pre>
  <p>It's possible in GSON, so I would expect that there must be some way in Jackson without modifying the Person class, without Java 8, and without an explicit custom deserializer. Does anybody know a solution?</p>
  <ul>
  <li>Update, additional info</li>
  </ul>
  <hr />
  <p>Gson seems to skip the argument constructor, so it must be creating a no-argument constructor behind the scenes using reflections.</p>
  <p>Also, there exists a <a href="https://github.com/FasterXML/jackson-module-kotlin" rel="nofollow noreferrer">Kotlin Jackson module</a> which is able to do this for Kotlin data classes, even without the &quot;-parameters&quot; compiler flag.
  So it is strange that such a solution doesn't seem to exist for Java Jackson.</p>
  <p>This is the (nice and clean) solution available in Kotlin Jackson (which IMO should also become available in Java Jackson via a custom module):</p>
  <pre><code>val mapper = ObjectMapper()
      .enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
      .registerModule(KotlinModule())     
          
  val person: Person = mapper.readValue(json, Person::class.java)
  </code></pre>