private static void writeGradleProject(@NotNull final IonWriter writer,
                                         @Nullable String fieldName,
                                         @NotNull final WriteContext context,
                                         @Nullable final GradleProject gradleProject) throws IOException {
    if (fieldName != null) {
      writer.setFieldName(fieldName);
    }
    if (gradleProject == null) {
      writer.writeNull();
      return;
    }
    context.gradleProjectsCollector.add(gradleProject, new ObjectCollector.Processor<IOException>() {
      @Override
      public void process(boolean isAdded, int objectId) throws IOException {
        writer.stepIn(IonType.STRUCT);
        writer.setFieldName(OBJECT_ID_FIELD);
        writer.writeInt(objectId);
        if (isAdded) {
          writeString(writer, "name", gradleProject.getName());
          writeString(writer, "description", gradleProject.getDescription());
          writeFile(writer, "projectDirectory", gradleProject.getProjectDirectory());
          writeProjectIdentifier(writer, context, gradleProject.getProjectIdentifier());
          writeFile(writer, "buildDirectory", gradleProject.getBuildDirectory());
          writeGradleProject(writer, "parent", context, gradleProject.getParent());

          writer.setFieldName("children");
          writer.stepIn(IonType.LIST);
          for (GradleProject ideaModule : gradleProject.getChildren()) {
            writeGradleProject(writer, null, context, ideaModule);
          }
          writer.stepOut();

          writeFile(writer, "buildScript", gradleProject.getBuildScript().getSourceFile());

          writer.setFieldName("tasks");
          writer.stepIn(IonType.LIST);
          for (GradleTask task : gradleProject.getTasks()) {
            writeGradleTask(writer, context, task);
          }
          writer.stepOut();
        }
        writer.stepOut();
      }
    });
  }
private static void writeGradleProject(@NotNull final IonWriter writer,
                                         @Nullable String fieldName,
                                         @NotNull final WriteContext context,
                                         @Nullable final GradleProject gradleProject)