title: How to configure Jackson to be able to deserialize special collections?
body: <p>I am wondering how to configure Jackson to deserialize a serialized list of objects that were contained in 'special' collections (immutable, or the result of collected stream).</p>
  
  <p>Here is my problem, for certain reasons, I need to declare de typing in jackson because I need to be able to deserialize everything and get back all my types.</p>
  
  <pre class="lang-java prettyprint-override"><code>
  public static class Sink {
      private List items;
  
      public Sink setItems(final List items) {
          this.items = items;
          return this;
      }
  
      public List getItems() {
          return this.items;
      }
  }
  
  public static void main(String[] args) throws Exception {
      final ObjectMapper mapper = new ObjectMapper();
      mapper.registerModule(new JavaTimeModule());
      mapper.registerModule(new Jdk8Module());
      mapper.registerModule(new AfterburnerModule());
      mapper.enableDefaultTyping(NON_FINAL, JsonTypeInfo.As.PROPERTY);
  
      String content = mapper.writeValueAsString(new Sink().setItems(List.of()));
      System.out.println(content);
      Sink result = mapper.readValue(content, Sink.class);
  }
  </code></pre>
  
  <p>But this has a nasty side effect with collections.
  The <code>content</code> value is: </p>
  
  <pre><code>{
      "@class": "api.Sink",
      "items": ["java.util.ImmutableCollections$ListN", []]
  }
  </code></pre>
  
  <p>And unfortunately, the <code>java.util.ImmutableCollections.*</code> do not have default constructors (which make sense).</p>
  
  <p><code>Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of</code>java.util.ImmutableCollections$ListN<code>(no Creators, like default construct, exist): no default no-arguments constructor found</code></p>
  
  <p>I am wondering how to force jackson to deserialize those kind of object as <code>ArrayList</code> or whatever type of list.</p>
  
  <p>I'd like to configure it to deserialize all sub types of list as <code>ArrayList</code> / <code>LinkedList</code> or when serializing to change the type of a collection</p>
  
  <p>(java 12 / jackson 2.9.7)</p>