RESTEasy's @Form

DZone 's Guide to

RESTEasy's @Form

· Java Zone ·
Free Resource

@Form is one of RESTEasy's best features. It encapsulates any set of inputs - path params, query params, form params, headers, cookies and PUT/POST body. NOTE: @Form does not ONLY encapsulate HTML Form input, although it can as described in my article about integrating RESTEasy with Spring MVC

Here's how it's used in an application:

public class MyForm {

   private int stuff;

   private String header;

   public void setFoo(String foo) {...}

public void post(@Form MyForm form) {...}


I've had HTTP input reuse in every big HTTP application that I've built in 3 organizations. 2 of the organizations used RESTEasy, and the results were a lot cleaner than the 3rd org with the use of @Form than with some of the "reuse hacks" I've had to do when using Jersey. Here are some other benefits I've had from @Form:

  • Input processing Logic: custom conversion, multi-variable processing (if param X isn't there, then param Y should be used in conjunction with header Z).
  • Content based security
  • Integration with JSR 303/Bean Validation (you can't use it unless you have a bean...). The processing happened via a RESETEasy interceptor. IMHO, the end result was elegant and simple.

I really hope that this feature gets into JAX-RS 2.0, although I think that the name would have to be more expressive than @Form.


From http://www.jroller.com/Solomon/entry/resteasy_s_form


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}