I’m using YamlDotNet to indent yaml files, and it works fine. However, when I do this, the final result also shows some changes in the values of some properties, such as:
- day: “Friday”
hours: [7, 17]
is transformed into:
- day: Friday
hours: - 7
- 17
Some more examples:
day_of_week: “Wednesday” => day_of_week: Wednesday
logfiles.download_enable: ‘on’ => logfiles.download_enable: on
I just want to indent the file, preserving the original values of the variables, as they are client files, I cannot change them.
var serializer = new SerializerBuilder()
//.WithNamingConvention(NullNamingConvention.Instance)
.WithIndentedSequences()
//.IgnoreFields()
.WithEventEmitter(nextEmitter => new QuoteSurroundingEventEmitter(nextEmitter))
//.JsonCompatible()
//.WithDefaultScalarStyle(ScalarStyle.Literal)
//.WithoutTypeInspector(inspector => )
//.WithoutTagMapping(typeof(Array))
//.ConfigureDefaultValuesHandling(DefaultValuesHandling.Preserve)
.Build();
return serializer.Serialize(yamlDictionary);
public class QuoteSurroundingEventEmitter : ChainedEventEmitter
{
public QuoteSurroundingEventEmitter(IEventEmitter nextEmitter) : base(nextEmitter)
{ }
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
{
eventInfo.Style = ScalarStyle.Plain;
base.Emit(eventInfo, emitter);
}
}
New contributor
José is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.