I have an OData api where we need to serialize DateTimes differently. For example, some properties need to be yyyy-mm-dd
, yyyy-MM-dd HH:mm:ss
or yyyy-MM-dd HH:mm
, etc.
I have read the following articles:
- .NET Core Web API with ODATA serializing DateTime
- Custom OData DateTime Serializer for .Net Core 3.1 Web Api
- WebAPI OData Datetime serialization
Plus a bunch of other searching online and trying different patterns but I cannot seem to get it to work. Basically all of those patterns treat all DateTimes the same. I need to be able to say if propertyName = "CalendarDate" serialize this way, if propertyName = "DateTimeIncludeSeconds" serialize that way, etc.
Any thoughts on how to conditionally set the format for DateTimes on a property by property basis in a .Net Core 3.1 OData api?