freemarker.template.utility

## Class DeepUnwrap

- java.lang.Object
- - freemarker.template.utility.DeepUnwrap

    public class DeepUnwrap
    extends Object

Utility methods for unwrapping `TemplateModel`-s.

### Constructor Summary

Constructors
Constructor and Description
`DeepUnwrap()`

### Method Summary

All Methods Static Methods Concrete Methods Deprecated Methods
`static Object` `permissiveUnwrap(TemplateModel model)` Same as `unwrap(TemplateModel)`, but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.
`static Object` `premissiveUnwrap(TemplateModel model)` Deprecated. the name of this method is mistyped. Use `permissiveUnwrap(TemplateModel)` instead.
`static Object` `unwrap(TemplateModel model)` Unwraps `TemplateModel`-s recursively.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DeepUnwrap

    public DeepUnwrap()

### Method Detail

#### unwrap

    public static Object unwrap(TemplateModel model)
                         throws TemplateModelException

Unwraps `TemplateModel`-s recursively. The converting of the `TemplateModel` object happens with the following rules:

1. If the object implements `AdapterTemplateModel`, then the result of `AdapterTemplateModel.getAdaptedObject(Class)` for `Object.class` is returned.
2. If the object implements `WrapperTemplateModel`, then the result of `WrapperTemplateModel.getWrappedObject()` is returned.
3. If the object is identical to the null model of the current object wrapper, null is returned.
4. If the object implements `TemplateScalarModel`, then the result of `TemplateScalarModel.getAsString()` is returned.
5. If the object implements `TemplateNumberModel`, then the result of `TemplateNumberModel.getAsNumber()` is returned.
6. If the object implements `TemplateDateModel`, then the result of `TemplateDateModel.getAsDate()` is returned.
7. If the object implements `TemplateBooleanModel`, then the result of `TemplateBooleanModel.getAsBoolean()` is returned.
8. If the object implements `TemplateSequenceModel` or `TemplateCollectionModel`, then a `java.util.ArrayList` is constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping).
9. If the object implements `TemplateHashModelEx`, then a `java.util.HashMap` is constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping).
10. Throw a `TemplateModelException`, because it doesn't know how to unwrap the object.

Throws:
  `TemplateModelException`

#### permissiveUnwrap

    public static Object permissiveUnwrap(TemplateModel model)
                                   throws TemplateModelException

Same as `unwrap(TemplateModel)`, but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.

Throws:
  `TemplateModelException`
Since:
  2.3.14

#### premissiveUnwrap

    @Deprecated
    public static Object premissiveUnwrap(TemplateModel model)
                                                throws TemplateModelException

Deprecated. the name of this method is mistyped. Use `permissiveUnwrap(TemplateModel)` instead.

Throws:
  `TemplateModelException`