Interface RestConverter
- All Known Implementing Classes:
Introspectable
,Queryable
,Traversable
Implements a filter mechanism for REST method calls that allows response objects to be converted to some other POJO after invocation of the REST method.
Converters are associated with REST methods through the following:
Example:
Converters can also be associated at the servlet level using the @Rest(converters)
annotation.
Applying converters at the resource level is equivalent to applying converters to each resource method individually.
How to implement
Implementers should simply implement theconvert(RestRequest, Object)
and return back a 'converted' object.
It's up to the implementer to decide what this means.
Subclasses must implement one of the following constructors:
public T();// No-arg constructor public T(ContextProperties);// Property store of the RestContext
Subclasses can also be defined as inner classes of the resource class.
Predefined converters
Traversable
- Allows URL additional path info to address individual elements in a POJO tree.Queryable
- Allows query/view/sort functions to be performed on POJOs.Introspectable
- Allows Java public methods to be invoked on the returned POJOs.
See Also:
-
Method Summary
Modifier and TypeMethodDescriptionconvert
(RestRequest req, Object res) Performs post-call conversion on the specified response object.
-
Method Details
-
convert
Performs post-call conversion on the specified response object.- Parameters:
req
- The servlet request.res
- The response object set by the REST method through theRestResponse.setContent(Object)
method.- Returns:
- The converted object.
- Throws:
BasicHttpException
- Thrown if any errors occur during conversion.SerializeException
- Generic serialization error occurred.
-