Skip to content

Add option to allow use of platform-linefeed (YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS) #84

@thauk-copperleaf

Description

@thauk-copperleaf

The behaviour I expect would be for the serializer to produce output with line endings consistent with that platform it's running on, unless explicitly overriden.

I'm just wondering if this is on purpose or not?

Deeper dive:

YAMLGenerator uses DumperOptions from snakeyaml and overrides some settings, but does not override the line ending setting:

protected DumperOptions buildDumperOptions(int jsonFeatures, int yamlFeatures,
org.yaml.snakeyaml.DumperOptions.Version version)
{
DumperOptions opt = new DumperOptions();
// would we want canonical?
if (Feature.CANONICAL_OUTPUT.enabledIn(_formatFeatures)) {
opt.setCanonical(true);
} else {
opt.setCanonical(false);
// if not, MUST specify flow styles
opt.setDefaultFlowStyle(FlowStyle.BLOCK);
}
// split-lines for text blocks?
opt.setSplitLines(Feature.SPLIT_LINES.enabledIn(_formatFeatures));
// array indentation?
if (Feature.INDENT_ARRAYS.enabledIn(_formatFeatures)) {
// But, wrt [dataformats-text#34]: need to set both to diff values to work around bug
// (otherwise indentation level is "invisible". Note that this should NOT be necessary
// but is needed up to at least SnakeYAML 1.18.
// Also looks like all kinds of values do work, except for both being 2... weird.
opt.setIndicatorIndent(1);
opt.setIndent(2);
}
return opt;
}

And since DumperOptions has the following default:
private LineBreak lineBreak = LineBreak.UNIX;

That results in output having Unix line endings, regardless of platform.

Alternatively, can you tell me how to produce YAML with platform-specific line endings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    yamlIssue related to YAML format backend

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions