score:0
i archived similar goal by using implicit class for actionbuilder
:
trait actionbuilderimplicits {
implicit class exactionbuilder[p](actionbuilder: actionbuilder[request, p])(implicit cc: controllercomponents) {
def validatejson[a](implicit executioncontext: executioncontext, reads: reads[a]): actionbuilder[request, a] = {
actionbuilder(cc.parsers.tolerantjson.validate(jsvalue => {
jsvalue.validate.aseither.left
.map(errors => badrequest(jserror.tojson(errors)))
}))
}
}
}
object actionbuilderimplicits extends actionbuilderimplicits
then in controller you can import actionbuilderimplicits
and use it as
action.validatejson[a].async { request =>
processingservice.process(request.body)
}
here is request.body
already type of a
Source: stackoverflow.com
Related Query
- How do I write a generic JSON parser in Play 2.7 for Scala that validates inbound requests?
- How do I write a JSON Format for an object in the Java library that doesn't have an apply method?
- How to write a Play JSON writes converter for a case class with a single nullable member
- How to parse json list or array in scala for play framework 2.2
- Scala Play - How to format Generics for JSON conversion
- Play 2.1(scala) - How to write Format[T] for scala enumeration case class
- How to write a symmetric Play Json formatter for a case class with one field in scala?
- How to write a Parser that validates its input against a predicate and otherwise fails
- How to write unit test for Play Framework JSON readers
- How do I write a query for mongodb using the casbah driver for scala that uses a substring and checks if the field is in a list of supplied values?
- How do I write a generic groupByKey for a Traversable[(K, V)] in scala <= 2.12
- Play JSON - How to generify this in Scala for Json handling?
- How to write a toCSV method for scala case class that would generate the csv string for the class?
- Scala Play framework json serializer for generic type
- How write Reads function for Scala Play
- How to define an implicit deserializer using Play Json for generic types
- How to write a Scala parser for paths?
- Play 2.6.x Scala How to Specify a TolerantText Body Parser for an Action
- How to write Java TestNG test class for scala play framework project?
- How to debug permgen memory errors for a project that uses sbt and play 2 framework in Scala
- How to write a exstension map inner for a generic iterator in scala without losing type information
- How to write an Scala parser for arithmetic operations including string?
- Scala play 2 framework how can I implement a write or format on Json
- How to write Scala Play framework custom class's multiple JSON serializer deserializer?
- How to swap implicit JSON formatter for two controller endpoints in Scala Play
- How to load JSON file using Play with Scala
- How do I write a scala unit test that ensures compliation fails?
- How to write copy() method for Simple Class in Scala
- Play Scala No Json deserializer found for type (String, String). Try to implement an implicit Reads or Format for this type
- Scala / Lift: How do I write unit tests that test a snippet's response to different parameters
More Query from same tag
- Use Scala Case Objects for Java Enums?
- How to override scala def close(): Future[Unit] in java
- Mixing pure and impure with Cats Effect
- Kafka transaction - skip one offset when the application stops and be started again
- Why arity-1 syntax in scala does not compile for self invocation?
- Spark Scala copy column from one dataframe to another
- Implement weak-referenced Eventbus actors?
- How do I control order of execution of exec statements in Gatling scenario?
- How to load SQL Database into Analytics for Apache Spark within Bluemix?
- sbt scala language server server crashed 5 times in last 3 minutes. The server will not be restarted
- Remove warning from scala: "It would fail on the following input: Nil"
- Scala-String filter operation from a new learner
- Compose stream of effects for http response
- Scala async vs. Java ForkJoinTask
- Apache Spark: trait calling implementation throws java.io.NotSerializableException on Column
- why self-type class can declare class
- Scala 2.8 breakOut
- Cache solution to manage external api calls using play framework
- How to convert a String-represented ByteBuffer into a byte array in Java
- How to Set List of System Properties On COmmand Line
- Gson toJson escapes fields that are Option
- scala.io.Source object empty after accessing with mkString?
- Mass-add an object if it is an instance of a class
- leaflet map does not appear correctly until resize
- Given events with start and end times, how to count the number of simultaneous events using Spark?
- How to use play framework FakeApplication() for multiple tests?
- Adding a new spark-package to scala spark
- Add a hook to Sentry Logback to scrub data
- When is the parentheses absolutely necessary in Scala?
- Pattern Matching in List[(Double, Double)] with param filter