I am reading yaml file with YamlReader(yamlbeans.YamlReader)
- tag: xyz
description: |
This is multi-line comment and I want to preserve
leading white spaces and new line
When I reads the above as given below:
String descr = tag.get("description");
It gives below output:
This is multi-line comment and I want to preserve
leading white spaces and new line
But I want to preserve leading white space.
Use an indentation indicator:
- tag: xyz
description: |1
This is a multi-line comment and I want to preserve
leading white spaces and new line
The 1
states that the following block scalar will have one space of additional indentation (in addition to the current indentation level) This will give:
This is a multi-line comment and I want to preserve
leading white spaces and new line
As you see, the two spaces present after the one indentation space in the block scalar are preserved. You can use any one-digit number as indentation indicator.
If you want to preserve trailing newline characters, use |1+
, where +
tells YAML to preserve trailing newline characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With