Interface ObjectWrapperAndUnwrapper

    • 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 be null.
        Since:
        2.3.22
        See Also:
        tryUnwrapTo(TemplateModel, Class)
    • Method Detail

      • tryUnwrapTo

        java.lang.Object tryUnwrapTo​(TemplateModel tm,
                                     java.lang.Class<?> targetClass)
                              throws TemplateModelException
        Attempts to unwrap a TemplateModel to a plain Java object that's the instance of the given class (or is null).
        Parameters:
        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.
        Returns:
        The unwrapped value that's either an instance of 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.
        Throws:
        TemplateModelException - If the unwrapping fails for a reason than doesn't fit the meaning of the CANT_UNWRAP_TO_TARGET_CLASS return value.
        Since:
        2.3.22
        See Also:
        unwrap(TemplateModel)