Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    if you are into video you can check out Mark Lewis' youtube videos https://www.youtube.com/channel/UCEvjiWkK2BoIH819T-buioQ
    joining a local meetup/user group could also be interesting
    N.S. Cutler
    James Roper published an interesting blog post several years ago on "Advanced Routing" in Play. Basically, roll your own Rails-style CRUD routing:

    He mentioned that:

    And I have some good news too, we will be introducing a feature like this into Play soon.

    I don't recall seeing anything like this in the official Play docs.

    Will Sargent
    @Aj3douglas in the old days, sysinternals had a tool you could use the find out who's locking a file: https://www.mysysadmintips.com/windows/clients/593-find-what-is-locking-a-file-using-sysinternals-process-explorer
    N.S. Cutler
    @wsargent yeah, checked that out previously. Think I'm looking for a code generator (which you just referenced in Scala Reddit thread on the subject) to handle CRUD boilerplate.
    So, if DB has a user table, generate the model, play form wrapper, and stubbed out CRUD controller methods along with corresponding GET/POST/PUT/DELETE routes.
    I don't mind play's default routing as text file approach, just don't want to do all the plumbing by hand.
    hi, is there a way to build play 2.8.x application from Gradle
    Joshua Goldberg
    Hey all, anyone here run scala play on heroku? I'm running into an issue where I'm trying to set up a job and run sbt to run a specific class with sbt "runMain com.example.Class" but I keep getting an error Expected whitespace character - has anyone encountered this before? Any work-around for it?
    @godenji There is the embedded play routing dsl https://www.playframework.com/documentation/2.8.x/ScalaSirdRouter
    I use that, because it is more powerfull, than the routes file, which cannot express certain wildcard routes, without generating unused errors
    and I like it over string programming
    Laszlo Konya
    Hi guys! I'd like to set the request timeout in Play! based on (https://www.playframework.com/documentation/2.8.x/SettingsAkkaHttp) and change the http response when it happens. Some thing like this: https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/timeout-directives/withRequestTimeoutResponse.html
    I tried to implement an error handler (https://www.playframework.com/documentation/2.8.x/ScalaErrorHandling) but they are not invoked (case no exception was thrown).
    Any suggestions?
    Sriraam A S
    Hey folks! After a scala 2.12 upgrade from scala 2.11, I am seeing slowdowns in tests in the order of few seconds. In particular, it takes longer for play service to start in our tests. Also, when running a lot of these tests in parallel, it seems to slow down even more. We are using play 2.7.x This was not the case in scala 2.11. Is anyone else seeing a slowdown during startup? Any known solutions?


    My application uses Play, ReactiveMongo Scala driver and Mongo DB. I have the following versions of these components:

    “com.typesafe.play” %% “play-json” % “2.5.18”
    “ai.x” %% “play-json-extensions” % “0.9.0”
    “com.typesafe.play” %% “play” % “2.5.18”
    “com.typesafe.play” %% “play-ws” % “2.5.18”
    “org.reactivemongo” %% “play2-reactivemongo” % “0.20.3-play25”
    “org.reactivemongo” %% “reactivemongo-play-json” % “0.20.3-play25”
    “org.reactivemongo” % “reactivemongo-bson_2.11” % “0.20.3”
    “org.reactivemongo” %% “reactivemongo” % “0.20.3”

    There is a JSON object in MongoDB that looks like this:
    “status” : {
    “siteStatus” : “InProgress”,
    “timestamp” : NumberLong(“1585696318513”),
    “timestampLocalDateTime” : “2020-03-31T23:11:58”

    When our application tries to read this object, we get this error:

    The attribute that is causing this error is this: “timestamp” : NumberLong(“1585696318513”). Play Framework expects it to be in this format: “timestamp” : “1585696318513” but Mongo DB stores it by adding some additional type information which they call Extended-JSON.

    The Scala class corresponding to this JSON is:

    case class TemplateSiteStatus(siteStatus: SiteStatus, timestamp: Long, timestampLocalDateTime: Option[LocalDateTime] = None, msg: Option[String] = None)

    object TemplateSiteStatus {
    implicit val format: OFormat[TemplateSiteStatus] = Json.format[TemplateSiteStatus]

    We never had any issues parsing this JSON when we were using the older version of the reactivemongo driver that is compatible with the following play-reactiveMongo framework:

    “org.reactivemongo” %% “play2-reactivemongo” % “0.12.4”

    This error only started happening after we upgraded to “play2-reactivemongo” % “0.20.3-play25”. Any idea how to work around this? We need to use the newer version for different reasons and cannot stay on the older version. Please help.

    Thank you.

    @onbvkkggjv is it your intention to use the very old version of play: 2.5?
    Loïc Descotte

    Hi ,

    do you know if it possible to use a custom mime type for ACCEPT header matching?

    I've tried that :
    val ACCEPT_CSV = Accepting("text/csv")
    val ACCEPT_CSV = Accepting("text/csv")
    render {
                case Accepts.Json() => [...]
                case ACCEPT_CSV => [...]
                case Accepts.Xml() => [...]
                case _ => [...]
    it never matches to CSV
    I'm testing with :
    route(app, FakeRequest(GET, url).withHeaders(("ACCEPT", "text/csv")))
    Loïc Descotte
    In debug mode I see that the the 2nd upply method is called :
    case class Accepting(mimeType: String) {
      def unapply(request: RequestHeader): Boolean               = request.accepts(mimeType)
      def unapply(mediaRange: play.api.http.MediaRange): Boolean = mediaRange.accepts(mimeType)
    Loïc Descotte
    (tested with "Accept" case too)
    Loïc Descotte
    mediaRange is equals to "text/csv" but mimeType is set to "application/xml", is it because it's not possible to match on default values?
    Loïc Descotte
    is it possible to force using the first unapply method (with request) ?
    Florian Fauvarque
    For info, we solved our issue by not using render, but instead:
    request.acceptedTypes.flatMap { mediaRange =>
      if (mediaRange.accepts(MimeTypes.JSON)) Some(JSON)
      else if (mediaRange.accepts(MimeTypes.JSON)) Some(XML)
      else if (mediaRange.accepts("text/csv")) Some(CSV)
      else None
    }.headOption match {
      case Some(JSON) => [...]
      case Some(XML) => [...]
      case Some(CSV) => [...]
      case _ => [...]


    I need to log metrics for requests in play framework, for example for the route

    /user/:userId             app.controllers.getUser(userId: String)

    in my customer filter I want to log the metrics for /user/:userId ie. the route and not the exact URI (/user/123, /user/345 etc).
    how do I go about getting the route from the request URI in the filter:

    class MetricsFilter @Inject()(implicit val mat: Materializer, ec: ExecutionContext, registry: MeterRegistry) extends Filter with Logging {
      override def apply(nextOperation: RequestHeader => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
        val chain = nextOperation(requestHeader)
    Ignasi Marimon-Clos
    Consider using action composition instead of a filter. Each action will need to explicitly call your instrumentation code but then you’ll be able to indicate an action name.
    Shawn Dhawan
    Hi, is there a way to apply a different error handler to a specific controller or route? (Preferably without modifying my current custom error handler specified in the application.conf)
    I'm trying to use a different error format for a specific group of routes.
    Antoine Doeraene
    hey there! Is there some play plugin or play-based library with an integrated "admin interface" similar to the one of Django? thanks!
    Artem Egorkine

    I have the weirdest of problems. I have the following code:

     case class SearchableValuesQuery(
        values: List[String],
        mode: Option[SearchMode] = Some(SearchMode.AND)
      object SearchableValuesQuery {
        implicit val jsonFormat: OFormat[SearchableValuesQuery] = Json.format[SearchableValuesQuery]

    Whenever I try to instantiate SearchValuesQuery, I get an UninitializedFieldError:

    Caused by: sbt.ForkMain$ForkError: scala.UninitializedFieldError: Uninitialized field: .../SearchService.scala: 201
        at ....SearchService$SearchableValuesQuery$.jsonFormat
    But everything works if I rewrite jsonFormat this way:
        implicit val jsonFormat: OFormat[SearchableValuesQuery] = new OFormat[SearchableValuesQuery] {
          override def writes(o: SearchableValuesQuery): JsObject = Json.writes[SearchableValuesQuery].writes(o)
          override def reads(json: JsValue): JsResult[SearchableValuesQuery] = Json.reads[SearchableValuesQuery].reads(json)
    How do I debug this?!
    Alexis Hernandez
    that's very likely when a val depends on another val that's defined after the first
    Artem Egorkine
    Thank you, apparently it was exactly that...
    How does it work when Format implicits are inside companion objects?
    I'm asking because in part of our code they are in companion objects and in part they are all together in one object. Would the former be a better strategy?
    German Greiner
    Hello everyone, can I assume that "request.id" will be unique through the lifetime of a play app instance? I'm specifically using API WebSocket.accept[In, Out]( request : RequestHeader => Flow[In, Out, _]) : WebSocket
    Alexej Haak
    Hey guys, I'm trying to use a TypedActor of the Form ActorRef[A[B]] with runtime injection, is it a known limitation that nested generics won't work? Guice doesnt find the type when I'm trying to inject it (ActorRef[C] is working) or am I doing something wrong most likely?
    Henri Cook
    Hi all, does anyone know if I can stop play-json outputting the _type field when encoding a sealed trait?
     "state": {
          "code": "errors.mismatch",
          "message": "Id '01713fcf-6ea4-75b3-8cc4-e57936be23e0' mismatched",
          "type": "failure",
          "_type": "ai.myproj.foo.api.SendToUserDto.FailureDto"
    Obvious solution is don't use a sealed trait, but i'm wondering if I can change the behaviour of the json encoder
    Artem Egorkine
    @henricook : we've used Jsonx.formatSealed from https://github.com/xdotai/play-json-extensions that guesses the correct class when the contents are unambiguously different at deserialization :)
    Henri Cook
    thanks Artem!