title: Java Spring, find with MongoTemplate and generic type
body: <p>
  I'm trying to build a query which returns a list of generic objects.</p>
  
  <p>It's my base object:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Getter
  @Setter
  @EqualsAndHashCode(of = {"id"})
  public class Normalized {
  
    public static final String J_ID = "id";
    public static final String J_CREATED_AT = "createdAt";
    public static final String J_UPDATED_AT = "udpatedAt";
  
    @Id
    @Indexed
    @JsonProperty(J_ID)
    private String id;
    @JsonProperty(J_CREATED_AT)
    private Instant createdAt;
    @JsonProperty(J_UPDATED_AT)
    private Instant updatedAt;
  
  }
  </code></pre>
  
  <p>It's my domain object:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Data
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  @EqualsAndHashCode(callSuper = true)
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Document    
  public class NormalizedContent&lt;E extends OriginalContent&gt; extends Normalized {
  
    public static final String J_SOURCE = "source";
    public static final String J_EXTERNAL_URL = "externalUrl";
    public static final String J_MAIN_TEXT = "mainText";
    public static final String J_ORIGINAL_CONTENT = "originalContent";
    public static final String J_CREATED_DATE = "createdDate";
  
    @Indexed
    @JsonProperty(J_SOURCE)
    private Sources source;
  
    @Indexed
    @JsonProperty(J_CREATED_DATE)
    private Instant createdDate;
  
    @JsonProperty(J_EXTERNAL_URL)
    private String externalUrl;
  
    @JsonProperty(J_MAIN_TEXT)
    private String mainText;
  
    @JsonProperty(J_ORIGINAL_CONTENT)
    private E originalContent;
  }
  </code></pre>
  
  <p>And it's a simplification of my function:</p>
  
  <pre class="lang-java prettyprint-override"><code>public Page&lt;NormalizedContent&lt;? extends OriginalContent&gt;&gt; findAllByQueriesAndFilters(
        List&lt;String&gt; queriesId, Pageable pageable) {
      if (queriesId == null || queriesId.isEmpty()) {
        throw new IllegalArgumentException("Queries unspecified");
      }
      Criteria criteria = Criteria.where(NormalizedContent.J_QUERY).in(queriesId);
      Query query = new Query(criteria);
      query.with(pageable);
      List&lt;NormalizedContent&lt;? extends OriginalContent&gt;&gt; content =
          mongoTemplate.find(query, NormalizedContent.class);
  
      Long total = mongoTemplate.count(query, OTBUserpanelUser.class);
  
      return new PageImpl&lt;NormalizedContent&lt;? extends OriginalContent&gt;&gt;(content, pageable, total);
    }
  </code></pre>
  
  <p>The problem is in the line:</p>
  
  <pre class="lang-java prettyprint-override"><code>List&lt;NormalizedContent&lt;? extends OriginalContent&gt;&gt; content =
              mongoTemplate.find(query, NormalizedContent.class);
  </code></pre>
  
  <p>Because the content variable is a list of <code>NormalizedContent&lt;? extends OriginalContent&gt;</code> and the find method returns a list of <code>NormalizedContent</code>.</p>
  
  <p>What can I do in order that the find method returns a list of <code>NormalizedContent&lt;? extends OriginalContent&gt;</code>?</p>