code: protected void writeMetadata() throws IOException {
      Set<GlobalMetadata> collectedMetadata = metadataCollector.getMetadataRecords();
  
      if (collectedMetadata.isEmpty()) {
        return;
      }
  
      String propName =
          ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.WRITER_METADATA_KEY, numBranches, branchId);
      String metadataStr;
      if (collectedMetadata.size() == 1) {
        metadataStr = collectedMetadata.iterator().next().toJson();
      } else {
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        boolean first = true;
  
        for (GlobalMetadata md : collectedMetadata) {
          if (!first) {
            sb.append(',');
          }
          sb.append(md.toJson());
          first = false;
        }
        sb.append(']');
        metadataStr = sb.toString();
      }
  
      this.properties.setProp(propName, metadataStr);
    }
docs: Write combined metadata to the {@link ConfigurationKeys#WRITER_METADATA_KEY} parameter.