Class DesignSpecIO
java.lang.Object
com.eqixiac.equinix.design.spec.DesignSpecIO
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 Summary
Modifier and TypeMethodDescriptionstatic Stringfingerprint(DesignSpec spec) The SHA-256 of the spec's canonical JSON (properties and map entries sorted), as lowercase hex.static DesignSpecParses a JSON document.static DesignSpecParses a YAML document.static DesignSpecReads a spec from a file, choosing the format by extension:.yaml/.ymlis YAML, anything else is JSON.static StringtoJson(DesignSpec spec) static StringtoYaml(DesignSpec spec) static voidwrite(DesignSpec spec, Path file) Writes a spec to a file, choosing the format by extension asread(Path)does.
-
Method Details
-
fromJson
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
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
Reads a spec from a file, choosing the format by extension:.yaml/.ymlis 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 readIllegalArgumentException- when the content is not a readable spec
-
write
Writes a spec to a file, choosing the format by extension asread(Path)does.- Parameters:
spec- the specfile- the file to write (UTF-8, replaced if present)- Throws:
UncheckedIOException- when the file cannot be written
-
toJson
- Parameters:
spec- the spec- Returns:
- indented JSON
-
toYaml
- Parameters:
spec- the spec- Returns:
- YAML
-
fingerprint
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
-