ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 8 forks source link

JsonSerializer TimeOnly Not Correct #798

Closed vzsoft closed 11 months ago

vzsoft commented 11 months ago

Describe the issue

Hi,

i try convert TimeOnly to json With TimeSpanHandler.StandardFormat result Not Correct JsonSerializer only save (hour and minute)

Reproduction

i need convert TimeOnly(12,1,2,3,4) to json JsonSerializer only save hour and minute => (12:01 PM)

JsConfig.TimeSpanHandler = TimeSpanHandler.StandardFormat;

var time = new TimeOnly(12,1,2,3,4);
var json1 = JsonSerializer.SerializeToString<TimeOnly>(time);  
//json1 Result: 12:01 PM

If Deserialize(12:01 PM) result is not equal to TimeOnly(12,1,2,3,4)

Expected behavior

StandardFormat should be this 12:01:02.003004 result without having dayPeriods (AM,PM)

i try use Newtonsoft.Json result correct

Newtonsoft.Json.JsonConvert.DefaultSettings = () => new Newtonsoft.Json.JsonSerializerSettings
{
   DateFormatHandling= Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
};

var time = new TimeOnly(12,1,2,3,4);
var json1 = Newtonsoft.Json.JsonConvert.SerializeObject(time);
//json1 Result: 12:01:02.003004

json1 Result: 12:01:02.003004

System Info

Windows 10
ServiceStack.Text 6.10

Additional context

sry my english not good

Validations

mythz commented 11 months ago

In ServiceStack.Text StandardFormat means to use .NET's default ToString() method which it does.

You can change how types are serialized with a custom type serializer: https://docs.servicestack.net/json-format#type-configuration

This is the 2nd time you've checked that your GitHub username is registered on Support page but I can't find your GitHub Username listed as a registered developer.

Please ensure your GitHub Username is registered Support contact before opening future issues.