How To Implement Input Validation For REST resources

How To Implement Input Validation For REST resources

The SaaS platform I’m working on has a RESTful interface that accepts XML payloads.rest-validation

Implementing REST Resources

For a Java shop like us, it makes sense to use JAX-B to generate JavaBean classes from an XML Schema. Working with XML (and JSON) payloads using JAX-B is very easy in a JAX-RS environment like Jersey:

@Path("orders")public class OrdersResource {  @POST  @Consumes({ "application/xml", "application/json" })  public void place(Order order) {    // Jersey marshalls the XML payload into the Order     // JavaBean, allowing us to write type-safe code     // using Order's getters and setters.    int quantity = order.getQuantity();    // ...  }}

Source : http://www.javacodegeeks.com/2013/08/how-to-implement-input-validation-for-rest-resources.html

Back to Top