// o is either a map already (string->object) or an arbitrary object, // in which case its fields are converted into a map. static Map objectToMap(O o) ctex { if (o instanceof Map) ret (Map) o; if (o == null) null; new TreeMap map; Class c = o.getClass(); while (c != Object.class) { Field[] fields = c.getDeclaredFields(); for (final Field field : fields) { if ((field.getModifiers() & Modifier.STATIC) != 0) continue; field.setAccessible(true); final Object value = field.get(o); if (value != null) map.put(field.getName(), value); } c = c.getSuperclass(); } // XXX NEW - hopefully this doesn't break anything if (o instanceof DynamicObject) putAll(map, o/DynamicObject.fieldValues); ret map; } // same for a collection (convert each element) static L> objectToMap(Iterable l) { if (l == null) null; new L x; for (O o : l) x.add(objectToMap(o)); ret x; }