Skip to content

Instantly share code, notes, and snippets.

View enterpredator's full-sized avatar

Eugene Smykov enterpredator

  • Moscow
View GitHub Profile
@enterpredator
enterpredator / Tuple2Format.scala
Created July 4, 2017 12:39 — forked from alexanderjarvis/Tuple2Format.scala
Allow case classes with Tuple2 types to be represented as a Json Array with 2 elements e.g. (Double, Double)
import play.api.libs.json._
import play.api.libs.functional.syntax._
import play.api.data.validation._
implicit def tuple2Reads[A, B](implicit aReads: Reads[A], bReads: Reads[B]): Reads[Tuple2[A, B]] = Reads[Tuple2[A, B]] {
case JsArray(arr) if arr.size == 2 => for {
a <- aReads.reads(arr(0))
b <- bReads.reads(arr(1))
} yield (a, b)
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("Expected array of two elements"))))
package controllers
import play.api._
import play.api.mvc._
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.format.Formats._
import models.Credential
import views.html.defaultpages.unauthorized
import scala.concurrent.Await