in freemarker-core/src/main/java/freemarker/template/DefaultObjectWrapper.java [188:256]
public TemplateModel wrap(Object obj) throws TemplateModelException {
if (obj == null) {
return super.wrap(null);
}
if (obj instanceof TemplateModel) {
return (TemplateModel) obj;
}
if (obj instanceof String) {
return new SimpleScalar((String) obj);
}
if (obj instanceof Number) {
return new SimpleNumber((Number) obj);
}
if (obj instanceof java.util.Date) {
if (obj instanceof java.sql.Date) {
return new SimpleDate((java.sql.Date) obj);
}
if (obj instanceof java.sql.Time) {
return new SimpleDate((java.sql.Time) obj);
}
if (obj instanceof java.sql.Timestamp) {
return new SimpleDate((java.sql.Timestamp) obj);
}
return new SimpleDate((java.util.Date) obj, getDefaultDateType());
}
final Class<?> objClass = obj.getClass();
if (objClass.isArray()) {
if (useAdaptersForContainers) {
return DefaultArrayAdapter.adapt(obj, this);
} else {
obj = convertArray(obj);
// Falls through (a strange legacy...)
}
}
if (obj instanceof Collection) {
if (useAdaptersForContainers) {
if (obj instanceof List) {
return DefaultListAdapter.adapt((List<?>) obj, this);
} else {
return forceLegacyNonListCollections
? new SimpleSequence((Collection<?>) obj, this)
: DefaultNonListCollectionAdapter.adapt((Collection<?>) obj, this);
}
} else {
return new SimpleSequence((Collection<?>) obj, this);
}
}
if (obj instanceof Map) {
return useAdaptersForContainers
? DefaultMapAdapter.adapt((Map<?, ?>) obj, this)
: new SimpleHash((Map<?, ?>) obj, this);
}
if (obj instanceof Boolean) {
return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
if (obj instanceof Iterator) {
return useAdaptersForContainers
? DefaultIteratorAdapter.adapt((Iterator<?>) obj, this)
: new SimpleCollection((Iterator<?>) obj, this);
}
if (useAdapterForEnumerations && obj instanceof Enumeration) {
return DefaultEnumerationAdapter.adapt((Enumeration<?>) obj, this);
}
if (iterableSupport && obj instanceof Iterable) {
return DefaultIterableAdapter.adapt((Iterable<?>) obj, this);
}
return handleUnknownType(obj);
}