liubiao4123 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

Regression: JsvSerializer.DeserializeFromString throws FormatException when deserializing DateTime in AR-SA culture #57

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

With CurrentUICulture/CurrentCulture set to AR-SA, attempt to deserialize a 
DateTime that does not contain a fractional time.  Full repro example below.

using System;
using System.Globalization;
using System.Threading;

namespace ServiceStackDateBug
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // This will work w/ all versions of ServiceStack.Text.dll.
            // Date will be serialized as 2011-02-07T09:02:03.001Z
            TestValues(1, 2, 3, 1);

            // This will only work w/ the oldest version.
            // Date will be serialized as 2011-02-07T01:02:03Z (no fractional time)
            TestValues(1, 2, 3, 0);
            Console.Read();
        }

        private static void TestValues(int hours, int minutes, int seconds, int millis)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
            Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentUICulture;

            var test = new TestDto { Date = DateTime.Today.AddHours(hours).AddMinutes(minutes).AddSeconds(seconds).AddMilliseconds(millis) };
            Console.WriteLine("Test date: {0}", test.Date);

            var serializer = new ServiceStack.Text.Jsv.JsvSerializer<TestDto>();
            var serialized = serializer.SerializeToString(test);

            Console.WriteLine("Serialized value: {0}", serialized);

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-sa");
            Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentUICulture;

            var deserializer = new ServiceStack.Text.Jsv.JsvSerializer<TestDto>();
            var deserialized = deserializer.DeserializeFromString(serialized);

            Console.WriteLine("Deserialized date (AR-SA): {0}", deserialized.Date);

            Console.WriteLine("Press any key to continue...");
            Console.Read();
            Console.WriteLine();
        }
    }

    public class TestDto
    {
        public DateTime Date { get; set; }
    }
}

What is the expected output? What do you see instead?

Expected: successful deserialization of the DateTime.

Actual: throws a FormatException, "The DateTime represented by the string is 
not supported in calendar System.Globalization.UmAlQuraCalendar."

What version of the product are you using? On what operating system?

ServiceStack.Text.dll v1.57

Please provide any additional information below.

This repros w/ v1.57 and v1.55, but does not repro w/ the older version of 
ServiceStack.Text.dll from March 2010.

Original issue reported on code.google.com by cw_sny...@hotmail.com on 8 Feb 2011 at 6:20

GoogleCodeExporter commented 8 years ago
Hi,

ServiceStack and all its sub projects have moved to GitHub.

The JsonSerializer and JSV/TypeSerializer are in the following location:
https://github.com/ServiceStack/ServiceStack.Text

Please re-try using the latest binaries and raise a GitHub issue ticket (or 
pull request) if the problem still exists.

Original comment by demis.be...@gmail.com on 8 Feb 2011 at 10:59