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

DateTime JSON compatible serialization doesn't put the date string in double quotes #587

Closed
mjeras opened this issue Feb 24, 2021 · 1 comment · Fixed by #768
Closed
Labels

Comments

@mjeras
Copy link

mjeras commented Feb 24, 2021

It seems that JsonEventEmitter doesn't set the eventInfo.Style correctly for DateTime, resulting in the date/time string ending up in single quotes what is not JSON compatible. For example:

using System;

using YamlDotNet.Serialization;

namespace YamlDotNetDateTimeBugReport
{
    class TestData
    {
        public DateTime Date => DateTime.Now;
    }

    class Program
    {
        static void Main(string[] args)
        {
            ISerializer jsonSerializer = new SerializerBuilder()
                .JsonCompatible()
                .Build();
            Console.WriteLine(jsonSerializer.Serialize(new TestData()));
        }
    }
}

results in

{"Date": '2021-02-24T10:20:12.3763590+01:00'}

The fix is simple, just adding
eventInfo.Style = ScalarStyle.DoubleQuoted;
under case TypeCode.DateTime in JsonEventEmitter.cs

@EdwardCooke
Copy link
Collaborator

This will be included in the next release.

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

Successfully merging a pull request may close this issue.

2 participants