Open Ancash opened 11 months ago
Using the following produces not the expected output (replaces the input with the output mentioned in the post before)
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test", Arrays.asList("&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers"));
System.out.println(yaml.saveToString());
but the following snippets do
YamlFile yaml = new YamlFile();
yaml.set("test", Arrays.asList("&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers"));
System.out.println(yaml.saveToString());
YamlFile yaml = new YamlFile();
yaml.set("test", "&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers");
System.out.println(yaml.saveToString());
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test", "&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers");
System.out.println(yaml.saveToString());
somehow leaving out the &8
makes it work
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test", Arrays.asList("%plugin_so-sum_{cat}_{sub-cat}% in %plugin_so-count_{cat}_{sub-cat}% offers"));
System.out.println(yaml.saveToString());
According to your examples seems to be an issue with list elements having some special characters while using the comment parser. With a simple string value does not happen 🤔
&
is used for key references in yaml (anchors and aliases):
https://yaml.org/spec/1.2.2/#692-node-anchors
Maybe is something related to that.
Try these other snippets independently and see if the same happens:
QuoteStyle.DOUBLE
as the third parameter in the set method to force double quotes.&8
but remove {
and }
characters.YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers"), QuoteStyle.DOUBLE);
System.out.println(yaml.saveToString());
outputs
test:
\ offers" \ offers"
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("&8%plugi_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers"));
System.out.println(yaml.saveToString());
outputs
test:
- '&8%plugi_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers'
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("&8%plugin_so-sum%&8 in &8%plugin_so-count%&8 offers"));
System.out.println(yaml.saveToString());
outputs
test:
- '&8%plugin_so-sum%&8 in &8%plugin_so-count%&8 offers'
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("abcd&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8 offers"));
System.out.println(yaml.saveToString());
outputs
test:
- abcd&8%plugin_so-sum_{cat}_{sub-cat}%&8 in &8%plugin_so-count_{cat}_{sub-cat}%&8
offers
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers"), QuoteStyle.DOUBLE);
System.out.println(yaml.saveToString());
outputs
test:
\ offers" \ offers"
YamlFile yaml = new YamlFile();
yaml.options().useComments(true);
yaml.set("test",Arrays.asList("&8%plugin_so-sum_cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers"));
System.out.println(yaml.saveToString());
outputs
test:
- '&8%plugin_so-sum_cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers'
using the following works in 1.7.3 but not in 1.8.1 1.8.2 1.8.3
YamlFile yaml = new YamlFile();
yaml.set("test",Arrays.asList("&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers"));
yaml = YamlFile.loadConfiguration(new StringReader(yaml.saveToString()), true);
System.out.println(yaml.saveToString());
Using SnakeYamlImplementation works. After some more testing it seems like SimpleYamlImplementation is having trouble with dumping multi line list elements.
DumperOptions dop = new DumperOptions();
dop.setWidth(10);
YamlFile yaml = new YamlFile();
yaml.set("test",Arrays.asList("&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers"), QuoteStyle.DOUBLE);
String savedToString = yaml.saveToString();
System.out.println(savedToString);
yaml = new YamlFile(new SimpleYamlImplementation(new LoaderOptions(), dop));
yaml.options().useComments(true);
yaml.loadFromString(savedToString);
System.out.println(yaml.saveToString());
outputs
test:
- "&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8\
\ offers"
test:
in &8%plugin_so-count_%cat%_%sub-cat%%&8
offers' offers'
where as
DumperOptions dop = new DumperOptions();
dop.setWidth(100);
YamlFile yaml = new YamlFile();
yaml.set("test",Arrays.asList("&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers"), QuoteStyle.DOUBLE);
String savedToString = yaml.saveToString();
System.out.println(savedToString);
yaml = new YamlFile(new SimpleYamlImplementation(new LoaderOptions(), dop));
yaml.options().useComments(true);
yaml.loadFromString(savedToString);
System.out.println(yaml.saveToString());
outputs
test:
- "&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8\
\ offers"
test:
- '&8%plugin_so-sum_%cat%_%sub-cat%%&8 in &8%plugin_so-count_%cat%_%sub-cat%%&8 offers'
Version: 1.8.4 i have a yaml file:
when i load it with YamlFile#load everything is fine. when i load it with YamlFile#loadWithComments the file now looks like this:
this is not the behaviour i expected because there are no "#" denoting a comment