T
- The type of object that this renderer knows how to render.public interface Renderer<T>
Renderers are typically not used directly.
Instead, they are used via by Context.render(Object)
method.
See RendererSupport
for support base class for implementations.
An alternative to implementing a renderer for a type is to make the type directly implement Renderable
.
RendererSupport
,
RenderableDecorator
,
Renderable
Modifier and Type | Method and Description |
---|---|
Class<T> |
getType()
The type of object that this renderer can render.
|
static <T> Renderer<T> |
of(Class<T> type,
BiConsumer<? super Context,? super T> impl)
Creates a renderer implementation from the given arguments.
|
void |
render(Context context,
T object)
Render the given object to the response.
|
static <T> TypeToken<Renderer<T>> |
typeOf(Class<T> typeToRender)
Creates a type token for a renderer of the given type of object.
|
static <T> Renderer<T> of(Class<T> type, BiConsumer<? super Context,? super T> impl)
T
- the type of object-to-rendertype
- the type of object-to-renderimpl
- the implementation of the render(Context, Object)
methodstatic <T> TypeToken<Renderer<T>> typeOf(Class<T> typeToRender)
T
- the type that the renderer renderstypeToRender
- the type that the renderer rendersClass<T> getType()
@NonBlocking void render(Context context, T object) throws Exception
Calling this method will finalize the processing, sending the response to the client.
Any errors that occur during rendering will be sent to Context.error(Throwable)
.
context
- the context for the operationobject
- the object to renderException
- if anything goes wrong while rendering