The return type of the Java method can be any serializable POJO as defined in {@doc jm.PojoCategories 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.
| @RestGet
| public String doGet() {
| return "Hello World!";
| }
In addition to POJOs, the following return types are also supported:
-
Parameters based on class types:
- Direct streams:
- {@link java.io.InputStream}
- {@link java.io.Reader}
- Apache HttpComponent beans:
- {@link org.apache.http.HttpEntity}
- {@link oaj.http.resource.HttpResource}
- {@link org.apache.http.HttpResponse}
- Standard HTTP response beans:
- {@link oaj.http.response.Accepted}
- {@link oaj.http.response.AlreadyReported}
- {@link oaj.http.response.BadRequest}
- {@link oaj.http.response.Conflict}
- {@link oaj.http.response.Continue}
- {@link oaj.http.response.Created}
- {@link oaj.http.response.EarlyHints}
- {@link oaj.http.response.ExpectationFailed}
- {@link oaj.http.response.FailedDependency}
- {@link oaj.http.response.Forbidden}
- {@link oaj.http.response.Found}
- {@link oaj.http.response.Gone}
- {@link oaj.http.response.HttpVersionNotSupported}
- {@link oaj.http.response.IMUsed}
- {@link oaj.http.response.InsufficientStorage}
- {@link oaj.http.response.InternalServerError}
- {@link oaj.http.response.LengthRequired}
- {@link oaj.http.response.Locked}
- {@link oaj.http.response.LoopDetected}
- {@link oaj.http.response.MethodNotAllowed}
- {@link oaj.http.response.MisdirectedRequest}
- {@link oaj.http.response.MovedPermanently}
- {@link oaj.http.response.MultipleChoices}
- {@link oaj.http.response.MultiStatus}
- {@link oaj.http.response.NetworkAuthenticationRequired}
- {@link oaj.http.response.NoContent}
- {@link oaj.http.response.NonAuthoritiveInformation}
- {@link oaj.http.response.NotAcceptable}
- {@link oaj.http.response.NotExtended}
- {@link oaj.http.response.NotFound}
- {@link oaj.http.response.NotImplemented}
- {@link oaj.http.response.NotModified}
- {@link oaj.http.response.Ok}
- {@link oaj.http.response.PartialContent}
- {@link oaj.http.response.PayloadTooLarge}
- {@link oaj.http.response.PermanentRedirect}
- {@link oaj.http.response.PreconditionFailed}
- {@link oaj.http.response.PreconditionRequired}
- {@link oaj.http.response.Processing}
- {@link oaj.http.response.RangeNotSatisfiable}
- {@link oaj.http.response.RequestHeaderFieldsTooLarge}
- {@link oaj.http.response.ResetContent}
- {@link oaj.http.response.SeeOther}
- {@link oaj.http.response.ServiceUnavailable}
- {@link oaj.http.response.SwitchingProtocols}
- {@link oaj.http.response.TemporaryRedirect}
- {@link oaj.http.response.TooManyRequests}
- {@link oaj.http.response.Unauthorized}
- {@link oaj.http.response.UnavailableForLegalReasons}
- {@link oaj.http.response.UnprocessableEntity}
- {@link oaj.http.response.UnsupportedMediaType}
- {@link oaj.http.response.UpgradeRequired}
- {@link oaj.http.response.UriTooLong}
- {@link oaj.http.response.UseProxy}
- {@link oaj.http.response.VariantAlsoNegotiates}
- Other:
- {@link oajr.beans.ChildResourceDescriptions}
- {@link oajr.beans.ResourceDescriptions}
- {@link oajr.beans.SeeOtherRoot}
- {@link java.lang.Throwable}
- Annotated parameters (either on the parameter or parameter type):
- {@link oaj.http.annotation.Response}
REST Java methods can also generate a response via the following:
-
By calling {@link oajr.RestResponse#setContent(Object)} with any of the types above.
-
By accessing the {@link java.io.Writer} directly by calling
{@link oajr.RestResponse#getNegotiatedWriter()} and writing the output yourself.
| // 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 by overriding {@link oajr.RestContext.Builder#createResponseProcessors(BeanStore,Supplier)}.