My question is very similar to this one however I don't have enough reputation to post a comment on the original answer.
I've got a custom class called FillPDF that I'm serializing on the server and deserializing on the client.
FillPDF dsPDF = JsonConvert.DeserializeObject<FillPDF>(json);
The FillPDF class consists of a DataSet property which contains a collection of DataTables
From reading the solution to the original question I'm aware of why the DateTime type is improperly being set as a String. I understand Json.Net's DataTableConverter infers each DataColumn.DataType by looking at the first row only (my first row has NULL values).
I tried to implement the solution from the original question. Dbc had suggested overriding the DataTableConverter. I've done it as such and I'm using the settings object during Serialization and Deserialization like so:
// Server
FillPDF pdfData = new FillPDF(strUniqueColID);
var settings = new JsonSerializerSettings { Converters = new[] { new TypeInferringDataTableConverter() } };
string json = JsonConvert.SerializeObject(pdfData, Formatting.Indented,settings);
// Client
var settings = new JsonSerializerSettings { Converters = new[] { new TypeInferringDataTableConverter() } };
FillPDF dsPDF = JsonConvert.DeserializeObject<FillPDF>(json,settings);
However I'm not getting any errors and my underlying DataTables are still not being correctly Deserialized. I assume this is because I'm serializing/deserializing a custom object as opposed to simply a DataTable like in the original question.
What I would like to be able to do is :
if(c.ColumnName.toLower().Contains("date"))
{
// Set Column's Type to DateTime because I know all Column Names containing "date" should be of type DateTime
}
Presumably this would have to be added to the overridden TypeInferringDataTableConverter.
I'm not too sure where to go from here, so I'm turning to SO in dire need of some help!
Thanks,
Justin.