public interface Renderer
{ renderer((value, ctx) -> { ... }); }Or from inside a module:
{ use((env, conf, binder) -> { Multibinder.newSetBinder(binder, Renderer.class) .addBinding() .toInstance((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.send(value.toString()); } });Or check for the
Accept
header:
renderer((value, ctx) -> { if (ctx.accepts("json")) { ctx.send(toJson(value)); } });API is simple and powerful!
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 | Field and Description |
---|---|
static com.google.inject.Key<Set<Renderer>> |
KEY
Renderer key.
|
Modifier and Type | Method and Description |
---|---|
default String |
name() |
static Renderer |
of(String name, Renderer renderer)
Renderer factory method.
|
void |
render(Object value, Renderer.Context ctx)
Render the given value and write the response (if possible).
|
default String name()
void render(Object value, Renderer.Context ctx) throws Exception
value
- Object to render.
ctx
- Rendering context.
Exception
- If rendering fails.
Copyright © 2019. All rights reserved.