Let's assume we have a sealed trait and some case class inheriting it:
sealed trait SomeTrait
final case class ClassA(somevalue : Int) extends SomeTrait
final case class ClassB(str : String) extends SomeTrait
(...)
Now I want to get all of these case classes extending the trait as a collection. How would I go on about that? In what kind of type would I even need to reference the classes? weakTypeTag
? Something else?
In a general sense, this is similar to Travis Brown's answer here about doing the same with case objects.
My application context: I have a HTTP server and a given file of case classes inheriting a single sealed trait (to be more exact: this hierarchy implements the Command Design Pattern). Now I want to automatically create an endpoint for a HTTP-POST per case class and parse incoming data via upickle
to the case class corresponding to that endpoint. Programmatrically I do not need the classes / types for anything other.