JsonSerializer TimeOnly Not Correct
Closed this issue · 1 comments
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 PMIf 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.003004json1 Result: 12:01:02.003004
System Info
Windows 10
ServiceStack.Text 6.10Additional context
sry my english not good
Validations
- Confirm Issue is reproducible from the information provided
- Have an active commercial ServiceStack License (GitHub Username is registered on Support page)
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.