kag0 kag0 -4 years ago 126
Scala Question

Play framework scala query binding for java class

I've got a java enum class

public enum MahEnum {
YUP, VALUES
}


and a scala query binding so that I can use that enum in routes

object MahBindings {
implicit def enumBinding = new QueryStringBindable[MahEnum] {
def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, MahEnum]] = ???
def unbind(key: String, value: Status): String = ???
}
}


How do I get play to recognize the bindings and apply them? If the bound class were in scala I could put the object in the scope of the class, but I've got a java enum.

Answer Source

Assuming your QueryStringBindable is already defined, you can import the implicits into the routes file with an sbt key. For Play 2.5.x and 2.4.x:

import play.sbt.routes.RoutesKeys

RoutesKeys.routesImport += "MahBindings._"

Play 2.3.x and prior:

PlayKeys.routesImport += "MahBindings._"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download