class MapConverter implements Converter {

    public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
        @SuppressWarnings("unchecked")
        Map<String, Object> data = (Map<String, Object>) source;
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            writer.startNode(entry.getKey());
            Object value = entry.getValue();
            if (value instanceof Map) {
                // Recursively map any sub-Maps
                this.marshal(value, writer, context);
            } else if (value instanceof Collection<?>) {
                context.convertAnother(value);
            } else {
                writer.setValue(value != null ? entry.getValue().toString() : null);
            }
            writer.endNode();
        }
    }

}