Skip to content

Commit

Permalink
Allow YamlOperator to dump any object type
Browse files Browse the repository at this point in the history
  • Loading branch information
samrocketman committed Jun 19, 2023
1 parent 6e9b540 commit a7172d8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/groovy/net/gleske/jervis/tools/YamlOperator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ class YamlOperator {

/**
Convert a POJO consisting of standard Java classes into a YAML string.
@param yamlToSerialize A map object consisting of standard Java class
instance objects.
@param yamlToSerialize A POJO consisting of standard Java class instance
objects.
@return A YAML-spec String.
*/
static String writeObjToYaml(Map yamlToSerialize) {
static String writeObjToYaml(def yamlToSerialize) {
DumperOptions options = new DumperOptions()
options.setIndent(2)
options.setPrettyFlow(true)
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
options.setIndicatorIndent(2);
options.setIndentWithIndicator(true);
def yaml = new Yaml(new SafeConstructor(new LoaderOptions()), new Representer(), options)
yaml.dumpAsMap(yamlToSerialize)
yaml.dump(yamlToSerialize)
}

/**
Convert a POJO consisting of standard Java classes into YAML written in a
file. This will overwrite the provided file if it exists.
@param destFile A file where the YAML output will be written.
@param yamlToSerialize A map object consisting of standard Java class
instance objects.
@param yamlToSerialize A POJO consisting of standard Java class instance
objects.
*/
static void writeObjToYaml(File destFile, Map yamlToSerialize) {
static void writeObjToYaml(File destFile, def yamlToSerialize) {
destFile.withWriter('UTF-8') { Writer w ->
w << writeObjToYaml(yamlToSerialize)
}
Expand Down

0 comments on commit a7172d8

Please sign in to comment.