#Saving Record object in a yaml file

3 messages · Page 1 of 1 (latest)

high harbor
#

So for context, I am trying to make a system which gets all the fields/parameters/components of the record and stores them in a yaml file. I tried doing this but it's not writting properly since it creates the file but then it writes !!me.mrafonso.configtest.TestRecord {} instead of a properly structed yaml file.
The record class only contains a String and an integer for both name and age (for testing)

I am using snakeyaml 2.0 to try to do this but I am unsure how to continue with this.

public static void saveConfig(Record record, Path filePath) {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setPrettyFlow(true);
    Yaml yaml = new Yaml(options);
    try (FileWriter writer = new FileWriter(filePath.toString())) {
        yaml.dump(record, writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
quaint craterBOT
#

This post has been reserved for your question.

Hey @high harbor! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.