private static void writeDependency(IonWriter writer, WriteContext context, IdeaDependency dependency) throws IOException {
    if (dependency instanceof IdeaModuleDependency) {
      writeModuleDependency(writer, context, (IdeaModuleDependency)dependency);
    }
    else if (dependency instanceof IdeaSingleEntryLibraryDependency) {
      writeLibraryDependency(writer, context, (IdeaSingleEntryLibraryDependency)dependency);
    }
    else {
      Object unpack = context.modelAdapter.unpack(dependency);
      if (unpack.getClass().getSimpleName().equals("DefaultIdeaModuleDependency")) {
        BackwardsCompatibleIdeaModuleDependency moduleDependency =
          context.modelAdapter.adapt(BackwardsCompatibleIdeaModuleDependency.class, unpack);
        writeModuleDependency(writer, context, moduleDependency);
      }
      else if (unpack.getClass().getSimpleName().equals("DefaultIdeaSingleEntryLibraryDependency")) {
        IdeaSingleEntryLibraryDependency libraryDependency = context.modelAdapter.adapt(IdeaSingleEntryLibraryDependency.class, unpack);
        writeLibraryDependency(writer, context, libraryDependency);
      }
    }
  }
private static void writeDependency(IonWriter writer, WriteContext context, IdeaDependency dependency)