Class WorkflowWriter

java.lang.Object
io.serverlessworkflow.api.WorkflowWriter

public class WorkflowWriter extends Object
Utility class for writing Serverless Workflow definitions to various outputs and formats.

This class provides static methods to serialize Workflow objects to files, streams, writers, byte arrays, or strings in either JSON or YAML format. The format is determined by the WorkflowFormat parameter or inferred from file extensions.

  • Method Details

    • writeWorkflow

      public static void writeWorkflow(OutputStream output, io.serverlessworkflow.api.types.Workflow workflow, WorkflowFormat format) throws IOException
      Writes a Workflow to the given OutputStream in the specified format.
      Parameters:
      output - the output stream to write the workflow to
      workflow - the workflow object to serialize
      format - the format to use (JSON or YAML)
      Throws:
      IOException - if an I/O error occurs during writing
    • writeWorkflow

      public static void writeWorkflow(Writer output, io.serverlessworkflow.api.types.Workflow workflow, WorkflowFormat format) throws IOException
      Writes a Workflow to the given Writer in the specified format.
      Parameters:
      output - the writer to write the workflow to
      workflow - the workflow object to serialize
      format - the format to use (JSON or YAML)
      Throws:
      IOException - if an I/O error occurs during writing
    • writeWorkflow

      public static void writeWorkflow(Path output, io.serverlessworkflow.api.types.Workflow workflow) throws IOException
      Writes a Workflow to the specified file path, inferring the format from the file extension.
      Parameters:
      output - the file path to write the workflow to
      workflow - the workflow object to serialize
      Throws:
      IOException - if an I/O error occurs during writing
    • writeWorkflow

      public static void writeWorkflow(Path output, io.serverlessworkflow.api.types.Workflow workflow, WorkflowFormat format) throws IOException
      Writes a Workflow to the specified file path in the given format.
      Parameters:
      output - the file path to write the workflow to
      workflow - the workflow object to serialize
      format - the format to use (JSON or YAML)
      Throws:
      IOException - if an I/O error occurs during writing
    • workflowAsString

      public static String workflowAsString(io.serverlessworkflow.api.types.Workflow workflow, WorkflowFormat format) throws IOException
      Serializes a Workflow to a string in the specified format.
      Parameters:
      workflow - the workflow object to serialize
      format - the format to use (JSON or YAML)
      Returns:
      the serialized workflow as a string
      Throws:
      IOException - if an error occurs during serialization
    • workflowAsBytes

      public static byte[] workflowAsBytes(io.serverlessworkflow.api.types.Workflow workflow, WorkflowFormat format) throws IOException
      Serializes a Workflow to a byte array in the specified format.
      Parameters:
      workflow - the workflow object to serialize
      format - the format to use (JSON or YAML)
      Returns:
      the serialized workflow as a byte array
      Throws:
      IOException - if an error occurs during serialization