com.github.jknack.handlebars
Class Jackson2Helper

java.lang.Object
  extended by com.github.jknack.handlebars.Jackson2Helper
All Implemented Interfaces:
Helper<Object>

public class Jackson2Helper
extends Object
implements Helper<Object>

A Jackson 2.x helper.

Basic usage:

  Handlebars hbs = new Handlebars();

  hbs.registerHelper("json", Jackson2Helper.INSTANCE);

  ...

  {{json model}}
 

View class usage:

  Handlebars hbs = new Handlebars();

  hbs.registerHelper("json", Jackson2Helper.INSTANCE);

  ...

  {{json model view="foo.MyView"}}

 

View alias usage:


  Handlebars hbs = new Handlebars();

  hbs.registerHelper("json", Jackson2Helper.INSTANCE
    .viewAlias("myView", foo.MyView.class));

  ...

  {{json model view="myView"}}

 

Since:
0.4.0
Author:
edgar.espina

Field Summary
static Helper<Object> INSTANCE
          A singleton version of Jackson2Helper.
 
Constructor Summary
Jackson2Helper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
          Creates a new Jackson2Helper.
 
Method Summary
 CharSequence apply(Object context, Options options)
           
 Jackson2Helper viewAlias(String alias, Class<?> viewClass)
          Add an alias for the given view class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final Helper<Object> INSTANCE
A singleton version of Jackson2Helper.

Constructor Detail

Jackson2Helper

public Jackson2Helper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Creates a new Jackson2Helper.

Parameters:
objectMapper - The object's mapper. Required.
Method Detail

apply

public CharSequence apply(Object context,
                          Options options)
                   throws IOException
Specified by:
apply in interface Helper<Object>
Throws:
IOException

viewAlias

public Jackson2Helper viewAlias(String alias,
                                Class<?> viewClass)
Add an alias for the given view class.

Parameters:
alias - The view alias. Required.
viewClass - The view class. Required.
Returns:
This helper.


Copyright © 2012. All Rights Reserved.