Created
August 7, 2017 19:12
-
-
Save patientplatypus/64f6e2bab930e8b2803b3d830733de8b to your computer and use it in GitHub Desktop.
im trying to get a simple read of some json object class in scala and running into trouble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import javax.inject._ | |
import play.api._ | |
import play.api.mvc._ | |
import play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
/** | |
* This controller creates an `Action` to handle HTTP requests to the | |
* application's home page. | |
*/ | |
case class Person(name: String, country: String, id: Int) | |
@Singleton | |
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { | |
/** | |
* Create an Action to render an HTML page. | |
* | |
* The configuration in the `routes` file means that this method | |
* will be called when the application receives a `GET` request with | |
* a path of `/`. | |
*/ | |
def index() = Action { implicit request: Request[AnyContent] => | |
Ok(views.html.index()) | |
} | |
def getName = Action { | |
Ok("Jim") | |
} | |
def parseJson(json: JsObject) = Action { implicit request => | |
val person = json(Seq(Person)) | |
Ok("name : " + person.name) | |
} | |
// implicit val placeReads: Reads[Place] = ( | |
// (JsPath \ "name").read[String] and | |
// (JsPath \ "location").read[Location] and | |
// (JsPath \ "residents").read[Seq[Resident]] | |
// )(Place.apply _) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment