Adds XML Validation and Databinding to the Play Framework
This Project is inspired by play-circe. It allows you to validate incoming XML and bind against generated case classes
To use, extend your Controller with the XmlValidatingBinder
trait and use the provided Action to modify the Request
@Singleton
class SampleController @Inject() extends Controller with XmlValidatingBinder {
def receiveXML(): Action[YourXmlClass] = Action.async(XmlValidatingBinder.bindXml[YourXmlClass]()) { request =>
Future {
val content : YourXmlClass = request.body
...
}
}
}
-
Build
TODO: This project has not been released to Maven yet. For now, you have to build and provide it yourself
sbt clean compile test publishLocal
-
Include Dependency
libraryDependencies += "de.codecentric" %% "play-xml-validate" % "0.0.1-SNAPSHOT",
-
Generate case classes with scalaxb
- include the scalaxb-sbt plugin in your
plugins.sbt
resolvers += Resolver.sonatypeRepo("public") addSbtPlugin("org.scalaxb" % "sbt-scalaxb" % "1.5.0")
- configure the scalaxb plugin in your
build.sbt
lazy val root = (project in file(".")). enablePlugins(PlayScala, ScalaxbPlugin). settings( scalaxbPackageName in(Compile, scalaxb) := "de.codecentric.play.xml.validate.sample", scalaxbXsdSource in(Compile, scalaxb) := baseDirectory.value / "conf" / "xsd" )
- include the scalaxb-sbt plugin in your
-
Include the XmlValidatingBinder in your controller by including the Trait and using the object method
@Singleton class SampleController @Inject() extends Controller with XmlValidatingBinder { def receiveXML(): Action[YourXmlClass] = Action.async(XmlValidatingBinder.bindXml[YourXmlClass]()) { request => Future { val content : YourXmlClass = request.body ... } } }
There is a comprehensive sample project in sample
This project supports Play 2.5.
We're relying on scalaxb for nearly everything