Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JAXB-based XML and JSON APIs
object Application extends Controller with JaxbSupport {
val paths: String = // colon-separated list of packages containing JAXB-annotated classes ...
val config: JSONConfiguration = // ...
// can be used for JAXB-based JSON and XML processing
implicit val context = new JSONJAXBContext(config, paths)
...
}
def postPersonXml = Action(jaxb.parse.xml[Person]) { request =>
val person: Person = request.body
// ...
}
def postPersonJson = Action(jaxb.parse.json[Person]) { request =>
val person: Person = request.body
// ...
}
def postPerson = Action(jaxb.parse[Person]) { request =>
val person: Person = request.body
// ...
}
def getPersonXml = Action {
val person: Person = ...
Ok(JaxbXml(person))
}
def getPersonJson = Action {
val person: Person = ...
Ok(JaxbJson(person))
}
def getPerson = Action { implicit request =>
val person: Person = ...
Ok(Jaxb(person)) // content negotiation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment