I defined a class
in models/ResponseQuery
as follows:
case class ResponseQuery(
query: String,
tableArray: Array[String]
)
In a file in app/controllers/
I return an object of type responseQuery
var responseQuery: models.ResponseQuery
Future.successful(Ok(responseQuery))
However, I get the following error while compiling:
Cannot write an instance of
models.ResponseQuery
toHTTP response
. Try to define aWriteable[models.ResponseQuery]
I appreciate any help in solving this error.
Try with companion object to ResponseQuery
and put implicit format for it.
import play.api.libs.json.Json
object ResponseQuery {
implicit format = Json.format[ResponseQuery]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.