{title:'Java Method Return Types', updated:'9.0.0'}

The return type of the Java method can be any serializable POJO as defined in POJO Categories. It can also be void if the method is not sending any output (e.g. a request redirect) or is setting the output using the {@link oajr.RestResponse#setContent(Object)} method.

Example:

| @RestGet | public String doGet() { | return "Hello World!"; | }

In addition to POJOs, the following return types are also supported:

REST Java methods can also generate a response via the following:

Example:

| // Equivalent method 1 | @RestGet("/example1/{personId}") | public Person doGet1(@Path("personId") UUID personId) { | Person person = getPersonById(personId); | return person; | } | | // Equivalent method 2 | @RestGet("/example2/{personId}") | public void doGet2(RestResponse res, @Path("personId") UUID personId) { | Person person = getPersonById(personId); | res.setContent(person); | }

Additional parameter types can be defined via the annotation {@link oajr.annotation.Rest#responseProcessors()} or by calling {@link oajr.RestContext.Builder#responseProcessors(Class...)}.

Example:

| @Rest( | responseProcessors={ MyResponseProcessor.class } // Option #1 - Via annotation | ) | public class MyResource extends BasicRestObject { | | // Option #2 - Programmatically | @RestInit | public void init(RestContext.Builder builder) { | builder.responseProcessors(MyResponseProcessor.class); | } | }