public class Jackson2Helper extends Object implements Helper<Object>
Basic usage:
Handlebars hbs = new Handlebars();
hbs.registerHelper("json", Jackson2Helper.INSTANCE);
...
{{json model}}
If model is null an empty string is returned.
You can change this using the default option:
{{json model default="{}"}}
Using a view class:
{{json model view="foo.MyView"}}
Using alias for views:
{{json model view="myView"}}
Escape HTML chars:
{{json model escapeHtml=true}}
Pretty printer:
{{json model pretty=true}}
| Modifier and Type | Field and Description |
|---|---|
static Helper<Object> |
INSTANCE
A singleton version of
Jackson2Helper. |
| Constructor and Description |
|---|
Jackson2Helper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Creates a new
Jackson2Helper. |
| Modifier and Type | Method and Description |
|---|---|
CharSequence |
apply(Object context,
Options options) |
Jackson2Helper |
viewAlias(String alias,
Class<?> viewClass)
Add an alias for the given view class.
|
public static final Helper<Object> INSTANCE
Jackson2Helper.public Jackson2Helper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Jackson2Helper.objectMapper - The object's mapper. Required.public CharSequence apply(Object context, Options options) throws IOException
apply in interface Helper<Object>IOExceptionpublic Jackson2Helper viewAlias(String alias, Class<?> viewClass)
alias - The view alias. Required.viewClass - The view class. Required.Copyright © 2013. All Rights Reserved.