title: No implicits arguments of type T, Trying to cast a dataframe to a Dataset[T]
body: <p>I'm trying to build a generic function to consolidate some mongoDb collections, I'm using case classes to type the collections and on my function I receive the type as a parameter <code>[T]</code> like this:</p>
  
  <pre><code>  def refreshCollection[T](newDS:Dataset[T],oldDS:Dataset[T]): Dataset[T]={
      val filteredOldDS=oldDS.join(newDS, Seq("id"),"left_anti").as[T]
      filteredOldDS.union(newDS)
    }
  </code></pre>
  
  <p>The problem is when I try to convert the Dataframe result of the join to the original case class using <code>.as[T]</code> to return a <code>Dataset[T]</code> I've got this error even tough I've imported the <code>sparkSession.implicits._</code>:</p>
  
  <pre><code>no implicit arguments of type: Encoder[T]
  </code></pre>
  
  <p>The interesting part is, when I make the conversion with a fixed case class works fine, any advice on this?</p>
  
  <p>Thanks in advance!</p>