public interface ObjectWrapperAndUnwrapper extends ObjectWrapper
ObjectWrapper that creates a plain Java object
from a TemplateModel. This is usually implemented by ObjectWrapper-s and reverses
ObjectWrapper.wrap(Object). However, an implementation of this interface should make a reasonable effort to
"unwrap" TemplateModel-s that wasn't the result of object wrapping (such as those created directly in FTL),
or which was created by another ObjectWrapper. The author of an ObjectWrapperAndUnwrapper should be
aware of the TemplateModelAdapter and WrapperTemplateModel interfaces, which should be used for
unwrapping if the TemplateModel implements them.
Experimental status warning: This interface is subject to change on non-backward compatible ways, hence, it shouldn't be implemented outside FreeMarker yet.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Object |
CANT_UNWRAP_TO_TARGET_CLASS
Indicates that while the unwrapping is maybe possible, the result surely can't be the instance of the
desired class, nor it can be
null. |
BEANS_WRAPPER, DEFAULT_WRAPPER, SIMPLE_WRAPPER| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
tryUnwrapTo(TemplateModel tm,
java.lang.Class<?> targetClass)
Attempts to unwrap a
TemplateModel to a plain Java object that's the instance of the given class (or is
null). |
java.lang.Object |
unwrap(TemplateModel tm)
Unwraps a
TemplateModel to a plain Java object. |
wrapstatic final java.lang.Object CANT_UNWRAP_TO_TARGET_CLASS
null.tryUnwrapTo(TemplateModel, Class)java.lang.Object unwrap(TemplateModel tm) throws TemplateModelException
TemplateModel to a plain Java object.null, if null is the appropriate Java value to represent
the template model. null must not be used to indicate an unwrapping failure. It must NOT be
CANT_UNWRAP_TO_TARGET_CLASS.TemplateModelException - If the unwrapping fails from any reason.tryUnwrapTo(TemplateModel, Class)java.lang.Object tryUnwrapTo(TemplateModel tm, java.lang.Class<?> targetClass) throws TemplateModelException
TemplateModel to a plain Java object that's the instance of the given class (or is
null).targetClass - The class that the return value must be an instance of (except when the return value is null).
Can't be null; if the caller doesn't care, it should either use {#unwrap(TemplateModel)}, or
Object.class as the parameter value.targetClass, or is null (if null
is the appropriate Java value to represent the template model), or is
CANT_UNWRAP_TO_TARGET_CLASS if the unwrapping can't satisfy the targetClass (nor the
result can be null). However, CANT_UNWRAP_TO_TARGET_CLASS must not be returned if the
targetClass parameter was Object.class.TemplateModelException - If the unwrapping fails for a reason than doesn't fit the meaning of the
CANT_UNWRAP_TO_TARGET_CLASS return value.unwrap(TemplateModel)