Below is the property in my model:
public DateTimeOffset AcquireDate { get; set; }
Below is the configuration in WebApiConfig:
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.Add(new XmlMediaTypeFormatter());
Below is the json response (date is in IS 8601 format):
acquireDate=2008-01-01T22:10:12+05:30
Below is the XML response (from fiddler):
AcquireDate
d4p1:DateTime
2008-01-01T16:40:12Z
d4p1:OffsetMinutes
330
In Xml response, datetime and offset are available in two different elements. I want DateTimeOffset as single value, just like json response (in ISO 8601 format).
I could use one more property which would be of type string and that way my problem could be solved (empty setter requires for this property to be serialized).
public string AcquireDateValue
{
get
{
return AcquireDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
}
set{}
}
Please suggest optimized solution apart from above if any.
Thank you.