Created
February 23, 2012 08:30
-
-
Save krasserm/1891558 to your computer and use it in GitHub Desktop.
JAXB-based XML and JSON APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def postPersonXml = Action(jaxb.parse.xml[Person]) { request => | |
val person: Person = request.body | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def postPersonJson = Action(jaxb.parse.json[Person]) { request => | |
val person: Person = request.body | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def postPerson = Action(jaxb.parse[Person]) { request => | |
val person: Person = request.body | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getPersonXml = Action { | |
val person: Person = ... | |
Ok(JaxbXml(person)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getPersonJson = Action { | |
val person: Person = ... | |
Ok(JaxbJson(person)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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