@SuppressWarnings("unchecked")
  @Override
  public T read(JsonReader in) throws IOException {
    List<Exception> exceptions = new ArrayList<>(subtypes.length);
    ReadAttempt attempt = readInAttempt(in);
    for (TypeAdapter<?> typeAdapter : adapters) {
      try {
        return (T) attempt.read(typeAdapter);
      } catch (Exception ex) {
        exceptions.add(ex);
      }
    }
    JsonParseException failure = new JsonParseException(
        String.format(
            "Cannot parse %s with following subtypes: %s",
            type,
            Arrays.toString(subtypes)));
    for (Exception exception : exceptions) {
      failure.addSuppressed(exception);
    }
    throw failure;
  }
Creates adapter from {@link Gson} and type tokens.
@param <T> the generic type
@param gson Gson instance
@param type supertype token
@param subtypes subtype tokens
@return subtype adapter
gson/src/org/immutables/gson/adapter/ExpectedSubtypesAdapter.java