code: public void toJson(JsonWriter jsonWriter, boolean keepConfig) throws IOException {
      jsonWriter.beginObject();
  
      jsonWriter.name("task id").value(this.getTaskId()).name("task state").value(this.getWorkingState().name())
          .name("start time").value(this.getStartTime()).name("end time").value(this.getEndTime()).name("duration")
          .value(this.getTaskDuration()).name("retry count")
          .value(this.getPropAsInt(ConfigurationKeys.TASK_RETRIES_KEY, 0));
  
      // Also add failure exception information if it exists. This information is useful even in the
      // case that the task finally succeeds so we know what happened in the course of task execution.
      if (getTaskFailureException().isPresent()) {
        jsonWriter.name("exception").value(getTaskFailureException().get());
      }
  
      if (keepConfig) {
        jsonWriter.name("properties");
        jsonWriter.beginObject();
        for (String key : this.getPropertyNames()) {
          jsonWriter.name(key).value(this.getProp(key));
        }
        jsonWriter.endObject();
      }
  
      jsonWriter.endObject();
    }
docs: Convert this {@link TaskState} to a json document.
  
  @param jsonWriter a {@link com.google.gson.stream.JsonWriter} used to write the json document
  @throws IOException