Package freemarker.template
Interface ObjectWrapperAndUnwrapper
-
- All Superinterfaces:
ObjectWrapper
- All Known Subinterfaces:
RichObjectWrapper
- All Known Implementing Classes:
BeansWrapper,DefaultObjectWrapper,SimpleObjectWrapper
public interface ObjectWrapperAndUnwrapper extends ObjectWrapper
Experimental - subject to change: Adds functionality toObjectWrapperthat 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 anObjectWrapperAndUnwrappershould be aware of theTemplateModelAdapterandWrapperTemplateModelinterfaces, which should be used for unwrapping if theTemplateModelimplements 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.ObjectCANT_UNWRAP_TO_TARGET_CLASSIndicates 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.ObjecttryUnwrapTo(TemplateModel tm, java.lang.Class<?> targetClass)Attempts to unwrap aTemplateModelto a plain Java object that's the instance of the given class (or isnull).java.lang.Objectunwrap(TemplateModel tm)Unwraps aTemplateModelto 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 aTemplateModelto a plain Java object.- Returns:
- The plain Java object. Can be
null, ifnullis the appropriate Java value to represent the template model.nullmust 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 aTemplateModelto 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.classas the parameter value.- Returns:
- The unwrapped value that's either an instance of
targetClass, or isnull(ifnullis the appropriate Java value to represent the template model), or isCANT_UNWRAP_TO_TARGET_CLASSif the unwrapping can't satisfy thetargetClass(nor the result can benull). However,CANT_UNWRAP_TO_TARGET_CLASSmust not be returned if thetargetClassparameter wasObject.class. - Throws:
TemplateModelException- If the unwrapping fails for a reason than doesn't fit the meaning of theCANT_UNWRAP_TO_TARGET_CLASSreturn value.- Since:
- 2.3.22
- See Also:
unwrap(TemplateModel)
-
-