YamlDotNet
YamlDotNet copied to clipboard
JSON incompatible value serialization when Emitter has bestWidth
trafficstars
When using a JSON compatible value serializer with a Emitter (which has a small bestWidth) the resulting string is no longer JSON compatible because of emitted newlines.
var emitter = new Emitter(someWriter, 2, 5);
var jsonSerializer = new SerializerBuilder().JsonCompatible().BuildValueSerializer();
//...
jsonSerializer.SerializeValue(emitter, "This is a #single# line string", typeof(string));
The hash character causes a double quoted string to be emitted. But because of the bestWidth of 5 in the emitter the string is writton on multiple lines.
Sample output:
key: "This
is a
#single#
line
string"
As .NET fiddle was not working when writing this I attached a sample code to this message: JsonBug.cs.txt