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