Class DesignSpecIO

java.lang.Object
com.eqixiac.equinix.design.spec.DesignSpecIO

public final class DesignSpecIO extends Object
Reads and writes a DesignSpec as JSON or YAML.

Reading is strict: an unknown property is an error (a typo in a hand-written spec must not be silently ignored) and enum values are matched case-insensitively. Reading does not validate the content; call DesignSpec.validate() or DesignSpec.requireValid().

  • Method Details

    • fromJson

      public static DesignSpec fromJson(String json)
      Parses a JSON document.
      Parameters:
      json - the document
      Returns:
      the spec (not yet validated)
      Throws:
      IllegalArgumentException - when the document is not a readable spec; the message names the location
    • fromYaml

      public static DesignSpec fromYaml(String yaml)
      Parses a YAML document.
      Parameters:
      yaml - the document
      Returns:
      the spec (not yet validated)
      Throws:
      IllegalArgumentException - when the document is not a readable spec; the message names the location
    • read

      public static DesignSpec read(Path file)
      Reads a spec from a file, choosing the format by extension: .yaml / .yml is YAML, anything else is JSON.
      Parameters:
      file - the file to read (UTF-8)
      Returns:
      the spec (not yet validated)
      Throws:
      UncheckedIOException - when the file cannot be read
      IllegalArgumentException - when the content is not a readable spec
    • write

      public static void write(DesignSpec spec, Path file)
      Writes a spec to a file, choosing the format by extension as read(Path) does.
      Parameters:
      spec - the spec
      file - the file to write (UTF-8, replaced if present)
      Throws:
      UncheckedIOException - when the file cannot be written
    • toJson

      public static String toJson(DesignSpec spec)
      Parameters:
      spec - the spec
      Returns:
      indented JSON
    • toYaml

      public static String toYaml(DesignSpec spec)
      Parameters:
      spec - the spec
      Returns:
      YAML
    • fingerprint

      public static String fingerprint(DesignSpec spec)
      The SHA-256 of the spec's canonical JSON (properties and map entries sorted), as lowercase hex.
      Parameters:
      spec - the spec
      Returns:
      64 hex characters, equal for equal content