Type List takes type parameters (Compilation Error in Play )

I currently learning the basics of RESTFUL API, with Play and am getting issues: am following some longtime tutorial and think am failing with right scala syntax! need help, thanks
here is the error…

        package controllers

import play.api.libs.json.Json
import javax.inject.Inject
import play.api.Configuration
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.concurrent.ExecutionContext


class PlacesController @Inject()(cc: ControllerComponents)(implicit assetsFinder: AssetsFinder, ec: ExecutionContext, configuration: Configuration)
  extends AbstractController(cc) {


  case class PlacesController(id: Int, name: String)

  val thePlaces: List = List(
    thePlaces(1, "newyork"),
    thePlaces(2, "chicago"),
    thePlaces(3, "capetown")
  )

  implicit val thePlacesWrites = Json.writes[PlacesController]

  def listPlaces = Action {
    val json = Json.toJson(thePlaces)
    Ok(json)
  }


}

As the error says, List is not a type but a parametrized type. Instead we have types like List[Int]. Perhaps what you want is a List[(Int, String)], as in

class PlacesController @Inject()(cc: ControllerComponents)(implicit assetsFinder: AssetsFinder, ec: ExecutionContext, configuration: Configuration)
  extends AbstractController(cc) {


  case class PlacesController(id: Int, name: String)

  val thePlaces: List[(Int, String)] = List(
    (1, "newyork"),
    (2, "chicago"),
    (3, "capetown")
  )

  implicit val thePlacesWrites = Json.writes[PlacesController]

  def listPlaces = Action {
    val json = Json.toJson(thePlaces)
    Ok(json)
  }


}

regards,
Siddhartha

2 Likes

@siddhartha-gadgil thanks alot, it worked I can now test my API