So I am trying to pattern match a List of a custom object which has been converted from Json. The compiler cannot determine the content of Sequences, e.g. List[Int] is the same as List[String] so I'm currently not able to differentiate between the different objects and therefore cannot handle them correctly.
I have retrieved Json data, transformed it and then successfully mapped it to my models so the myFunction (below) is the part which is causing the problem - in not being able to identify the data type:
trait SuperT
case class User(firstname: String, firstname: String, dob: Option[Date]) extends SuperT
case class Country(name: String, continent: Option[String], hemisphere: Option[String]) extends SuperT
def myFunction(jsRes: JsResult[Seq[SuperT]])(implicit request: Request[AnyContent]) = {
jsRes match {
case JsSuccess(data: List[SuperT], path: JsPath) => data match {
// cannot find the differences between the following 2 case types
case u: List[User] => Ok(views.html.db.user.index(Some(u))
case c: List[RgnM] => Ok(views.html.db.country.index(Some(c))
}
case e: JsError => Ok(JsError.toJson(e))
}
}
Any help or insight is appreciated!