NewtonSoft.Json custom JsonConverter deserialize to DateTime not working NewtonSoft.Json custom JsonConverter deserialize to DateTime not working json json

NewtonSoft.Json custom JsonConverter deserialize to DateTime not working


I'm pretty sure all you need to do is call serializer.Deserialize. Doing this will advance the reader correctly and you shouldn't need to do anything else:

public class UnixTimestampJsonConverter : JsonConverter{    public override object ReadJson(        JsonReader reader,        Type objectType,        object existingValue,        JsonSerializer serializer)    {        long ts = serializer.Deserialize<long>(reader);        return TimeUtils.GetMbtaDateTime(ts);    }    public override  bool CanConvert(Type type)    {        return typeof(DateTime).IsAssignableFrom(type);    }    public override void WriteJson(        JsonWriter writer,        object value,        JsonSerializer serializer)    {        throw new NotImplementedException();    }    public override bool CanRead    {         get { return true; }     }}

Example: https://dotnetfiddle.net/Fa8Zis