In Spark, I can do both:
case class MyObj(val i: Int, val j: String) import org.apache.spark.sql.{Encoder, Encoders} implicit val myEncoder: Encoder[MyObj] = Enc