diff --git a/webapp/src/freemarker/ext/dump/BaseDumpDirective.java b/webapp/src/freemarker/ext/dump/BaseDumpDirective.java index 18c8778a5..17eaacfcb 100644 --- a/webapp/src/freemarker/ext/dump/BaseDumpDirective.java +++ b/webapp/src/freemarker/ext/dump/BaseDumpDirective.java @@ -323,13 +323,21 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel { TemplateModelIterator iModel = keys.iterator(); while (iModel.hasNext()) { String key = iModel.next().toString(); - // Workaround this oddity: model.object does not contain + // Work around this oddity: model.object does not contain // values for "empty" and "keys", but model.keys() does. if ("class".equals(key) || "empty".equals(key)) { continue; } TemplateModel value = model.get(key); - items.put(key, getDump(value)); + // A map with exposed methods includes methods inherited from Map and Object like + // size(), getClass(), etc. Punt on these for now by suppressing in the dump, + // though this is not the optimal solution. If they are exposed to the templates, + // the dump should also expose them. I'm guessing that in most cases these + // methods are not relevant to template authors. + if (! (value instanceof TemplateMethodModel)) { + items.put(key, getDump(value)); + } + } map.put(Key.VALUE.toString(), items); return map; diff --git a/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java b/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java index b11b016fb..98195738e 100644 --- a/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java +++ b/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java @@ -654,11 +654,6 @@ public class DumpDirectiveTest { test(varName, dataModel, expectedDump); } - - @Test - public void dumpHash() { - - } @Test public void dumpStringToStringMap() { @@ -1039,6 +1034,7 @@ public class DumpDirectiveTest { private int id; private String middleName; private List favoriteColors; + // private Map degrees; private Employee supervisor; private float salary; @@ -1071,6 +1067,10 @@ public class DumpDirectiveTest { favoriteColors.add(color); } } + +// void setDegrees(Map degrees) { +// this.degrees = degrees; +// } float getSalary() { return salary; @@ -1127,6 +1127,10 @@ public class DumpDirectiveTest { return favoriteColors; } +// public Map getDegrees() { +// return degrees; +// } + public String familyName() { return lastName; } @@ -1141,6 +1145,11 @@ public class DumpDirectiveTest { jdoe.setFavoriteColors("blue", "green"); jdoe.setSalary(65000); +// Map degrees = new HashMap(); +// degrees.put("BA", "Mathematics"); +// degrees.put("MS", "Computer Science"); +// jdoe.setDegrees(degrees); + c.clear(); c.set(1975, Calendar.OCTOBER, 25); c = DateUtils.truncate(c, Calendar.DATE); @@ -1158,7 +1167,7 @@ public class DumpDirectiveTest { Map supervisorExpectedDump = new HashMap(); supervisorExpectedDump.put(Key.TYPE.toString(), "freemarker.ext.dump.DumpDirectiveTest$Employee"); - supervisorExpectedDump.put(Key.VALUE.toString(), getJaneSmithExpectedDump(exposureLevel)); + supervisorExpectedDump.put(Key.VALUE.toString(), getJaneSmithExpectedDump(exposureLevel)); // Properties SortedMap propertiesExpectedDump = new TreeMap(); @@ -1198,6 +1207,7 @@ public class DumpDirectiveTest { marriedExpectedDump.put(Key.VALUE.toString(), true); propertiesExpectedDump.put("married", marriedExpectedDump); + propertiesExpectedDump.put("supervisor", supervisorExpectedDump); Map favoriteColorsExpectedDump = new HashMap(); @@ -1213,6 +1223,22 @@ public class DumpDirectiveTest { favoriteColorListExpectedDump.add(color2ExpectedDump); favoriteColorsExpectedDump.put(Key.VALUE.toString(), favoriteColorListExpectedDump); propertiesExpectedDump.put("favoriteColors", favoriteColorsExpectedDump); + +// This test fails, don't know why +// Map degreesExpectedDump = new HashMap(); +// degreesExpectedDump.put(Key.TYPE.toString(), Type.HASH); +// Map> degreeMapExpectedDump = new HashMap>(); +// Map degree1ExpectedDump = new HashMap(); +// degree1ExpectedDump.put(Key.TYPE.toString(), Type.STRING); +// degree1ExpectedDump.put(Key.VALUE.toString(), "Mathematics"); +// degreeMapExpectedDump.put("BA", degree1ExpectedDump); +// Map degree2ExpectedDump = new HashMap(); +// degree2ExpectedDump.put(Key.TYPE.toString(), Type.STRING); +// degree2ExpectedDump.put(Key.VALUE.toString(), "Computer Science"); +// degreeMapExpectedDump.put("MS", degree2ExpectedDump); +// degreesExpectedDump.put(Key.VALUE.toString(), degreeMapExpectedDump); +// propertiesExpectedDump.put("degrees", degreesExpectedDump); + } expectedDump.put(Key.PROPERTIES.toString(), propertiesExpectedDump); @@ -1315,6 +1341,10 @@ public class DumpDirectiveTest { favoriteColorListExpectedDump.add(color2ExpectedDump); favoriteColorsExpectedDump.put(Key.VALUE.toString(), favoriteColorListExpectedDump); propertiesExpectedDump.put("favoriteColors", favoriteColorsExpectedDump); + +// Map degreesExpectedDump = new HashMap(); +// degreesExpectedDump.put(Key.VALUE.toString(), Value.NULL); +// propertiesExpectedDump.put("degrees", degreesExpectedDump); } expectedDump.put(Key.PROPERTIES.toString(), propertiesExpectedDump);