use of freemarker.template.TemplateHashModelEx2 in project freemarker by apache.
the class DeepUnwrapTest method testHashEx2Unwrapping.
@SuppressWarnings("rawtypes")
@Test
public void testHashEx2Unwrapping() throws Exception {
Map<Object, Object> map = new LinkedHashMap<Object, Object>();
map.put("k1", "v1");
map.put("k2", null);
map.put(3, "v3");
map.put(null, "v4");
DefaultObjectWrapper dow = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_27).build();
TemplateModel model = dow.wrap(map);
assertSame(map, DeepUnwrap.unwrap(model));
Object unwrapped = DeepUnwrap.unwrap(new PurelyTemplateHashModelEx2((TemplateHashModelEx2) model));
assertNotSame(map, unwrapped);
assertEquals(map, unwrapped);
// Order is kept:
assertArrayEquals(new Object[] { "k1", "k2", 3, null }, ((Map) unwrapped).keySet().toArray());
}
use of freemarker.template.TemplateHashModelEx2 in project freemarker by apache.
the class Listables method getMapsWrappedAsEx2.
/**
* Returns the map wrapped on various ways.
*/
private List<TemplateHashModelEx2> getMapsWrappedAsEx2(Map<?, ?> map) throws TemplateModelException {
List<TemplateHashModelEx2> maps = new ArrayList<TemplateHashModelEx2>();
maps.add((SimpleHash) new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_0).build().wrap(map));
maps.add((DefaultMapAdapter) new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_24).build().wrap(map));
BeansWrapperBuilder bwb = new BeansWrapperBuilder(Configuration.VERSION_2_3_24);
bwb.setSimpleMapWrapper(true);
maps.add((TemplateHashModelEx2) bwb.build().wrap(map));
return maps;
}
Aggregations