This is a configuration issue on my WebAPI application.
When I pass this date as JSON from my Angular project to my WebAPI project it looks like this: created: "2019-01-09T16:16:06.149Z"
After it passes through Deserialization at WebAPI, it looks like this:
UPDATE: Initially, I was skeptical that this was a JSON.Net thing. But, as looked at my models more carefully, I realized this IS a JSON.Net. I have a base class that contains my "Created", "Updated" fields. Address inherits this class. HomeAddress inherits Address. This must be too much for JSON.Net to handle. When I removed the Inheritance from the Base class, and put my Created and Updated members on HomeAddress. It worked! So, this question really pertains to JSON.Net's capability to merge inherited members sourced in a base class.
WebAPIConfig.cs (no JSON.Net configuration for dates):
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{...}
}
WebAPI Controller:
[RoutePrefix("parents")]
public class ParentsController : ApiController
{
[HttpPost]
[Route("update")]
public bool UpdateParentInfo(Parent parent)
{
// when I inspect parent.Homeaddress.Created I get the DateTime().Min
}
}
HomeAddress.cs nested in Parent.cs:
public class Parent
{
[JsonProperty("parentID")]
public Guid ParentID { get; set; }
[JsonProperty("homeAddress")]
public Address HomeAddress { get; set; }
public Parent()
{
this.HomeAddress = new HomeAddress();
}
}
HomeAddress.cs:
public class HomeAddress: Address
{
public HomeAddress(){}
}
Address.cs
public class Address: Base
{
[JsonProperty("addressID")]
[Key]
public Guid AddressID { get; set; }
[JsonProperty("street1")]
public string Street1 { get; set; }
[JsonProperty("city")]
public string City { get; set; }
[JsonProperty("state")]
public string State { get; set; }
[JsonProperty("zip")]
public string Zip { get; set; }
}
Base.cs
public class Base
{
[JsonProperty("created")]
public DateTime Created { get; set; }
}
This date is in a nested object.
Can JSON.Net Detect Inherited Members -- this deep? Thanks for the help.
My short answer: No. And I'm running away from the abstraction as fast I can type. I'm putting my Created/Updated members in the HomeAddress class. And calling it a day.