You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't find why when I specify string with leading space in some line it is stored as DoubleQuoted instead of Literal.
Example:
classProgram{staticvoidMain(string[]args){varserializer=newSerializerBuilder().WithEventEmitter(e =>newLiteralMultilineEventEmitter(e)).Build();varobj="line with leading space \nother line";Console.WriteLine(serializer.Serialize(obj));}privateclassLiteralMultilineEventEmitter:ChainedEventEmitter{publicLiteralMultilineEventEmitter(IEventEmitternextEmitter):base(nextEmitter){}publicoverridevoidEmit(ScalarEventInfoeventInfo,IEmitteremitter){if(eventInfo.Source.Type==typeof(string)&&eventInfo.Source.Valueisstringvalue&&value.Contains("\n")){eventInfo.Style=ScalarStyle.Literal;}base.Emit(eventInfo,emitter);}}}
Returns:
"line with leading space \nother line"
While if I change value obj value to:
varobj="line with leading space\nother line";
without space then it is serialized right:
|-
line with leading space
other line
I've debug code to Emitter where I can see that this is expected behavior, but I can't find such behavior in documentation.
More over even if I will try to read this Literal string from YAML it will be deserialized right as expected:
staticvoidMain(string[]args){varserializer=newSerializerBuilder().WithEventEmitter(e =>newLiteralMultilineEventEmitter(e)).Build();varobj="line with leading space \nother line";Console.WriteLine(serializer.Serialize(obj));varyaml="|-\r\n"+" line with leading space \r\n"+" other line";vardeserializer=newDeserializerBuilder().Build();vardeserializedValue=deserializer.Deserialize<string>(yaml);Console.WriteLine(deserializedValue);Console.WriteLine(deserializedValue==obj);}
With output:
line with leading space
other line
True
The text was updated successfully, but these errors were encountered:
I found the same issue. It's due to the internal check for valid literal strings in Yaml not permitting spaces prior to line breaks. I wrote an event emitter to "clean" up these strings as we wanted all literal strings to appear that way and trailing space removal wouldn't break the data (it contained Html / JavaScript etc).
I can't find why when I specify string with leading space in some line it is stored as
DoubleQuoted
instead ofLiteral
.Example:
Returns:
While if I change value
obj
value to:without space then it is serialized right:
I've debug code to Emitter where I can see that this is expected behavior, but I can't find such behavior in documentation.
More over even if I will try to read this
Literal
string from YAML it will be deserialized right as expected:With output:
The text was updated successfully, but these errors were encountered: