Package freemarker.template
Interface ObjectWrapperAndUnwrapper
-
- All Superinterfaces:
ObjectWrapper
- All Known Subinterfaces:
RichObjectWrapper
- All Known Implementing Classes:
BeansWrapper
,DefaultObjectWrapper
,RhinoWrapper
,SimpleObjectWrapper
public interface ObjectWrapperAndUnwrapper extends ObjectWrapper
Experimental - subject to change: Adds functionality toObjectWrapper
that creates a plain Java object from aTemplateModel
. This is usually implemented byObjectWrapper
-s and reversesObjectWrapper.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 anotherObjectWrapper
. The author of anObjectWrapperAndUnwrapper
should be aware of theTemplateModelAdapter
andWrapperTemplateModel
interfaces, which should be used for unwrapping if theTemplateModel
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.
- Since:
- 2.3.22
-
-
Field Summary
Fields Modifier and Type Field 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 benull
.-
Fields inherited from interface freemarker.template.ObjectWrapper
BEANS_WRAPPER, DEFAULT_WRAPPER, SIMPLE_WRAPPER
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Object
tryUnwrapTo(TemplateModel tm, java.lang.Class<?> targetClass)
Attempts to unwrap aTemplateModel
to a plain Java object that's the instance of the given class (or isnull
).java.lang.Object
unwrap(TemplateModel tm)
Unwraps aTemplateModel
to a plain Java object.-
Methods inherited from interface freemarker.template.ObjectWrapper
wrap
-
-
-
-
Field Detail
-
CANT_UNWRAP_TO_TARGET_CLASS
static final 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 benull
.- Since:
- 2.3.22
- See Also:
tryUnwrapTo(TemplateModel, Class)
-
-
Method Detail
-
unwrap
java.lang.Object unwrap(TemplateModel tm) throws TemplateModelException
Unwraps aTemplateModel
to a plain Java object.- Returns:
- The plain Java object. Can be
null
, ifnull
is the appropriate Java value to represent the template model.null
must not be used to indicate an unwrapping failure. It must NOT beCANT_UNWRAP_TO_TARGET_CLASS
. - Throws:
TemplateModelException
- If the unwrapping fails from any reason.- Since:
- 2.3.22
- See Also:
tryUnwrapTo(TemplateModel, Class)
-
tryUnwrapTo
java.lang.Object tryUnwrapTo(TemplateModel tm, java.lang.Class<?> targetClass) throws TemplateModelException
Attempts to unwrap aTemplateModel
to a plain Java object that's the instance of the given class (or isnull
).- Parameters:
targetClass
- The class that the return value must be an instance of (except when the return value isnull
). Can't benull
; if the caller doesn't care, it should either use {#unwrap(TemplateModel)}, orObject.class
as the parameter value.- Returns:
- The unwrapped value that's either an instance of
targetClass
, or isnull
(ifnull
is the appropriate Java value to represent the template model), or isCANT_UNWRAP_TO_TARGET_CLASS
if the unwrapping can't satisfy thetargetClass
(nor the result can benull
). However,CANT_UNWRAP_TO_TARGET_CLASS
must not be returned if thetargetClass
parameter wasObject.class
. - Throws:
TemplateModelException
- If the unwrapping fails for a reason than doesn't fit the meaning of theCANT_UNWRAP_TO_TARGET_CLASS
return value.- Since:
- 2.3.22
- See Also:
unwrap(TemplateModel)
-
-