public interface Renderer
{ renderer((value, ctx) -> { ... }); }Or from inside a module:
{ use((env, conf, binder) -> { Multibinder.newSetBinder(binder, Renderer.class) .addBinding() .toInstance(renderer((value, ctx) -> { ... })); }); }Inside a
Renderer
you can do whatever you want. For example you can check for a specific
type:
renderer((value, ctx) -> { if (value instanceof MyObject) { ctx.text(value.toString()); } });For check for the
Accept
header:
renderer((value, ctx) -> { if (ctx.accepts("json")) { ctx.text(toJson(value)); } });API is simply and powerful! It is so powerful that you can override any of the existing built-in renderers, because application specific renderers has precedence over built-in renderers.
Modifier and Type | Interface and Description |
---|---|
static interface |
Renderer.Context
Contains a few utility methods for doing the actual rendering and writing.
|
Modifier and Type | Method and Description |
---|---|
void |
render(Object value,
Renderer.Context ctx)
Render the given value and write the response (if possible).
|
void render(Object value, Renderer.Context ctx) throws Exception
value
- Object to render.ctx
- Rendering context.Exception
- If rendering fails.Copyright © 2015. All rights reserved.