public class DecoratorConverter<T> extends AbstractConfigurationAware implements ContextConverter
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addContextConverter(
decorate(String.class).compute("reverse", s -> new StringBuilder(s).reverse().toString()).build())
.build();
engine.compileMustache("{{reverse}}").render("Foo");
By default, the converter is applied if the runtime class of the context
object is assignable to the delegate type. A custom predicate can be used but
beware of generics pitfalls and ClassCastExceptions.
Note that ReflectionResolver and MapResolver must be
registered in order to make it work.
| Modifier and Type | Class and Description |
|---|---|
static class |
DecoratorConverter.Builder<T> |
configurationDEFAULT_PRIORITY| Modifier and Type | Method and Description |
|---|---|
Object |
convert(Object from) |
static <T> DecoratorConverter.Builder<T> |
decorate(Class<T> delegateType)
Returns a decorator converter builder for the specified delegate type.
|
static <T> DecoratorConverter.Builder<T> |
decorate(Predicate<Object> test)
Returns a decorator converter builder with the specified predicate used to
test a context object.
|
checkNotInitialized, init, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPriorityisValidgetConfigurationKeys, initpublic static <T> DecoratorConverter.Builder<T> decorate(Class<T> delegateType)
delegateType - public static <T> DecoratorConverter.Builder<T> decorate(Predicate<Object> test)
delegateType - Copyright © 2020. All rights reserved.