code: private static Map<String, Object> expandObject(Map<FieldPath, Object> data) {
      Map<String, Object> result = new HashMap<>();
  
      SortedSet<FieldPath> sortedFields = new TreeSet<>(data.keySet());
  
      FieldPath lastField = null;
  
      for (FieldPath field : sortedFields) {
        if (lastField != null && lastField.isPrefixOf(field)) {
          throw new IllegalArgumentException(
              String.format("Detected ambiguous definition for field '%s'.", lastField));
        }
  
        List<String> segments = field.getSegments();
        Object value = data.get(field);
        Map<String, Object> currentMap = result;
  
        for (int i = 0; i < segments.size(); ++i) {
          if (i == segments.size() - 1) {
            currentMap.put(segments.get(i), value);
          } else {
            if (!currentMap.containsKey(segments.get(i))) {
              currentMap.put(segments.get(i), new HashMap<>());
            }
  
            currentMap = (Map<String, Object>) currentMap.get(segments.get(i));
          }
        }
  
        lastField = field;
      }
  
      return result;
    }
docs: Turns a field map that contains field paths into a nested map. Turns {a.b : c} into {a : {b :
  c}}.