code: public void write(JsonGenerator jsonGenerator) throws IOException {
      jsonGenerator.writeStartObject();
  
      // nameToNode begins
      jsonGenerator.writeFieldName("nameToNode");
      jsonGenerator.writeStartObject();
      for (Map.Entry<String, ClusterNode> entry : nameToNode.entrySet()) {
        jsonGenerator.writeFieldName(entry.getKey());
        entry.getValue().write(jsonGenerator);
      }
      jsonGenerator.writeEndObject();
      // nameToNode ends
  
      // hostsToSessions begins
      // We create a new Map of type <ClusterNode.name, Set<SessionIds>>.
      // The original hostsToSessions map has the ClusterNode as its key, and
      // we do not need to persist the entire ClusterNode again, since we have
      // already done that with nameToNode.
      Map<String, Set<String>> hostsToSessionsMap =
        new HashMap<String, Set<String>>();
      for (Map.Entry<ClusterNode, Set<String>> entry :
        hostsToSessions.entrySet()) {
        hostsToSessionsMap.put(entry.getKey().getName(),
          entry.getValue());
      }
      jsonGenerator.writeObjectField("hostsToSessions", hostsToSessionsMap);
      // hostsToSessions ends
  
      jsonGenerator.writeObjectField("nameToApps", nameToApps);
  
      // faultManager is not required
  
      // We can rebuild the loadManager
      jsonGenerator.writeEndObject();
    }
docs: This method writes the state of the NodeManager to disk
  @param jsonGenerator The instance of JsonGenerator, which will be used to
  write JSON to disk
  @throws IOException