Serializing XML DateTime for Servicestack.net

Is there a way to override XML serialization of DateTime in Servicestack.Net, as we can do with JSON:

JsConfig<DateTime>.SerializeFn = date => new DateTime(date.Ticks, DateTimeKind.Local).ToString("dd.MM.yyyy HH:mm:ss"); 

I want to do the same for all XML DateTimes.

Edit:

I just found out that I can associate XML serialization with this:

 this.ContentTypeFilters.Register("application/xml", SerializeXmlToStream, DeserializeXmlFromStream); public static void SerializeXmlToStream(IRequestContext requestContext, object response, Stream stream) { using (var sw = new StreamWriter(stream)) { sw.Write(response.ToXml()); } } 

This returns the same XML as without it. If anyone knows how I can change serialization of DateTime to a custom format using this or any other global way, please let me know.

+6
source share

Source: https://habr.com/ru/post/984547/


All Articles