I have the following piece of code
import play.api.i18n.{MessagesApi, Messages, I18nSupport}
import play.api.libs.json.Json
case class HttpMessage(key: String, message: String)
object HttpMessage {
implicit val jsonFormat = Json.format[HttpMessage]
def apply(key: String): HttpMessage = {
HttpMessage(key, Messages(key))
}
}
When compiled, it throws
[error] could not find implicit value for parameter messages: play.api.i18n.Messages
[error] HttpMessage(key, messages(key))
[error] ^
I made some research and it seems that it cannot find an implicit
value for MessagesAPI
. It seems it must be inject like in controllers but I do not know how because I am facing an object
and case class
here. @Inject
annotation is not accepted.
How can I fix this?
@Singleton
? – tzortzikimport play.api.Play.current import play.api.i18n.Messages.Implicits._
, it should work, but Play.current approach is deprecated. – insan-e