code: public String permissionsToYml(Collection<Permission> permissions) {
          try {
              Map<String, Map<String, Set<Permission>>> map = new TreeMap<>();
              permissions.forEach(permission -> {
                  map.putIfAbsent(permission.getMsName(), new TreeMap<>());
                  map.get(permission.getMsName()).putIfAbsent(permission.getRoleKey(), new TreeSet<>());
                  map.get(permission.getMsName()).get(permission.getRoleKey()).add(permission);
              });
              return mapper.writeValueAsString(map);
          } catch (Exception e) {
              log.error("Failed to create permissions YML file from collection, error: {}", e.getMessage(), e);
          }
          return null;
      }
docs: Convert permissions collection to yml string.
  
  @param permissions collection
  @return yml string