def validateInput[A](json:JsValue)(func: A => Future[Result]):Future[Result]= {
implicit val format = Json.format[A]
json.validate[A].fold(
errors => {
Future(BadRequest(JsError.toJson(errors)))
},
validObj =>
func(validObj)
)
}
[error] D:\program\ymgl\back\app\controllers\Security.scala:114: No unapply or unapplySeq function found[error] implicit val format = Json.format[A][error] ^[error] D:\program\ymgl\back\app\controllers\Security.scala:115: No Json deserializer found for type A. Try an implicit Reads or Format for this type.[error] json.validate[A].fold([error] ^[error] two errors founddef validateInput[A: Reads](json:JsValue)(func: A => Future[Result]): Future[Result]
Then remove your Json.format[A] and declare your implicit Format for each type you want to serialize in its companion object, or wherever it's convenient for you.
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f1c388a7-5516-47b3-b9e0-161f7bfe4d12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def validateInput[A : Reads ](json:JsValue)(func: A => Future[Result]):Future[Result]= {
import models.JsonFormats._
json.validate[A].fold(
errors => {
Future(BadRequest(JsError.toJson(errors)))
},
validObj =>
func(validObj)
)
}
object JsonFormats {
import play.api.libs.json.Json
implicit val objectIdFormat = Json.format[ObjectId]
}
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f1c388a7-5516-47b3-b9e0-161f7bfe4d12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/c0e04c6f-36f1-4535-8a4b-48f402665953%40googlegroups.com.