Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline simple key #547

Open
kosorin opened this issue Nov 26, 2020 · 1 comment
Open

Multiline simple key #547

kosorin opened this issue Nov 26, 2020 · 1 comment
Labels

Comments

@kosorin
Copy link

kosorin commented Nov 26, 2020

I want new line as a key

"\n": xyz

but I always get something like this

? >2

: xyz

even if I emit scalar key with DoubleQuoted style, it's still complex key

? "\n"
: xyz

I think simple key can be multiline and this code should be deleted.

if (scalarData.isMultiline)
{
return false;
}

Otherwise this if will never be true.
if (isSimpleKeyContext && scalarData.isMultiline)
{
style = ScalarStyle.DoubleQuoted;
}

@EdwardCooke
Copy link
Collaborator

The following code illustrates the single line key not roundtripping as expected

using YamlDotNet.Serialization;

var deserializer = new DeserializerBuilder().Build();
var serializer = new SerializerBuilder().Build();


var yaml = "\"\\n\": xyz";
var a = deserializer.Deserialize<object>(yaml);
var b = serializer.Serialize(a);
Console.WriteLine(yaml);
Console.WriteLine("====");
Console.WriteLine(b);
Console.WriteLine("====");
var c = deserializer.Deserialize<object>(b);
var d = serializer.Serialize(c);
Console.WriteLine(d);
Console.WriteLine("====");

var e = new Test { Prop = "xyz" };
var f = serializer.Serialize(e);
Console.WriteLine(f);
Console.WriteLine("====");


public class Test
{
    [YamlMember(Alias = "\n")]
    public string Prop { get; set; }
}

Results:

"\n": xyz
====
? >2

: xyz

====
'': xyz

====
? '

'
: xyz

====

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants