I am making a prototype project of NodaTime compared to BCL's DateTime, but executing this result gives me recursionLimit exceeded error.
This is the function I am using to JSONify my viewmodel. The error happens after this function returns.
[HttpPost]
public JsonResult GetDates(int numOfDatesToRetrieve)
{
List<DateTimeModel> dateTimeModelList = BuildDateTimeModelList(numOfDatesToRetrieve);
JsonResult result = Json(dateTimeModelList, JsonRequestBehavior.AllowGet);
return result;
}
My view model is built properly when I inspected it. Here is the code for my view model.
public class DateTimeModel
{
public int ID;
public LocalDateTime NodaLocalDateTimeUTC;
public LocalDateTime NodaLocalDateTime
{
get
{
DateTimeZone dateTimeZone = DateTimeZoneProviders.Bcl.GetZoneOrNull(BCLTimezoneID);
//ZonedDateTime zonedDateTime = NodaLocalDateTimeUTC.InUtc().WithZone(dateTimeZone);
OffsetDateTime offsetDateTime = new OffsetDateTime(NodaLocalDateTimeUTC, Offset.Zero);
ZonedDateTime zonedDateTime = new ZonedDateTime(offsetDateTime.ToInstant(), dateTimeZone);
return zonedDateTime.LocalDateTime;
}
}
public OffsetDateTime NodaOffsetDateTime;
public DateTime BclDateTimeUTC;
public DateTime BclLocalDateTime
{
get
{
DateTime utcDateTime = DateTime.SpecifyKind(BclDateTimeUTC, DateTimeKind.Utc);
TimeZoneInfo nzTimeZone = TimeZoneInfo.FindSystemTimeZoneById(BCLTimezoneID);
DateTime result = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, nzTimeZone);
return result;
}
}
public DateTimeOffset BclDateTimeOffset;
//public int Offset;
public string OriginalDateString;
public string BCLTimezoneID;
}
I am sure that the NodaTime objects are not serializing correctly because when I comment the code from the viewModel the JsonResult is able to execute.
I read this off this page NodaTime API Reference
Code in this namespace is not currently included in Noda Time NuGet packages; it is still deemed "experimental". To use these serializers, please download and build the Noda Time source code from the project home page.
So I downloaded and built the source code and replaced the dll's my project references but I don't know how to implement the JsonSerialization classes.
Can someone explain to me how to use NodaTime.Serialization.JsonNet classes to make my NodaTime objects serializable?