Releases: Carleslc/Simple-YAML
1.8.4
1.8.3
1.8.2
1.8.1
1.8
The examples have been improved with the new features:
- YamlExample -> test.yml
- YamlCommentsExample -> test-comments.yml
- YamlCommentsFormatExample -> test-comments-format.yml
- YamlQuoteStyleExample -> test-quote-style.yml
Comment Fixes
- #42 Fixes issues with
#
character inside values or side comments
Comment Formatting
- #53 Header behaviour has changed to be more intuitive. Now the header is considered to be the first block comment until a blank line (i.e. with no direct key below), instead of everything above the first key like before. The comment on the first key does not overlap anymore with the header. The header and the first key comment are separated by a blank line.
- Footer methods have been added for the last comment of the file without any key below.
- You can customize the header format using
yamlFile.options().headerFormatter(YamlHeaderFormatter)
. - #53 #54 Comments now can be formatted, either by default or per comment.
Now it is possible to format comments using prefixes and suffixes, globally or per comment, taking into account blank lines as comments, with some configurations available for reading comments (for instance stripping the # prefix and stripping trailing or leading blank lines), using an instance of YamlCommentFormatter or a custom format implementing CommentFormatter.
Some formatters are available with the YamlCommentFormat
enum. For instance, the following will add blank lines above of the comments you add on keys with indent 0:
yamlFile.setCommentFormat(YamlCommentFormat.PRETTY);
The default prefix is "# "
for block comments and " # "
for side comments. You can change them to add blank lines above or below the comments, or to add more spaces, # characters or section dividers.
Examples:
Changing Quote Style
- #50 Change the quote style using
yamlFile.options().quoteStyleDefaults()
.
You can change the default quote style for all values or for specific value types.
yamlFile.set("quote", "This is double quote style", QuoteStyle.DOUBLE);
More information here.
List indexing
You can use list indexing to select list values with array notation. This is especially useful if you want to get a single element, set a comment on a specific index or set different comments on list values that are not unique.
Negative indexing is allowed (list[-1]
is the last element).
See the example with values and example with comments.
Other features
- An alternative API has been added using the
path(String)
method to set comments along with values without repeating the path.
yamlFile.path("test.hello")
.set("Hello")
.comment("Block comment")
.commentSide("Side comment");
- Path separator can be escaped with
\
character prefix, for instancegetString("a\.b.c")
selectsa\.b
->c
. In previous versions that would have beena\
->b
->c
. This is for specific scenarios, but if you usually have dots in keys consider changing the path separator to something else like/
, in that casegetString("a.b/c")
selectsa.b
->c
.
Implementation abstraction
Now the snakeyaml implementation is decoupled from YamlConfiguration
class.
You can access to the implementation if needed with getImplementation()
:
SnakeYamlImplementation implementation = (SnakeYamlImplementation) yamlFile.getImplementation();
org.yaml.snakeyaml.Yaml yaml = implementation.getYaml();
You can also provide a custom implementation using yamlFile.setImplementation(YamlImplementation)
if you don't want to use snakeyaml.
More information here.
@Deprecated
If you were loading a file with loadConfiguration(Reader)
or loadConfiguration(InputStream)
those methods have been deprecated. Use loadConfiguration(SupplierIO.Reader)
or loadConfiguration(SupplierIO.InputStream)
instead:
Change YamlFile.loadConfiguration(new BufferedReader(...))
to YamlFile.loadConfiguration(() -> new BufferedReader(...))
or YamlFile.loadConfiguration(new FileInputStream(file))
to YamlFile.loadConfiguration(() -> new FileInputStream(file))
.
Previously while loading or saving a file the whole file was stored in a String in memory before parsing or dumping the yaml file. This is acceptable for small to medium configuration files, but now writing the yaml in memory to a StringBuilder is not required, so this is an improvement in memory usage.
1.7.3
1.7.2
1.7.1
- Fixes loading paths with spaces #30
- Added YamlFile constructors for URL and URI.
- Added static methods to load YamlFile with readers or streams:
loadConfiguration(Reader reader, boolean withComments)
andloadConfiguration(InputStream stream, boolean withComments)
- Removed
saveWithComments
andsaveToStringWithComments
methods. Nowsave
andsaveToString
will save comments if the YamlFile was loaded withloadWithComments
or a comment is set withsetComment
. - Now list elements indentation is consistent with
yamlFile.options().indent()
(2 by default).
1.7
1.6.1
- Default encoding is now UTF-8 instead system default.
If desired, you can change the encoding to use your system's default charset or any other with:
yamlFile.options().charset(Charset.defaultCharset());
copyDefaults
is nowtrue
by default.