public void FromAndToString() { var payload = new byte[] { 3, 15, 254 }; var issued = new DateTimeOffset(2018, 10, 9, 14, 21, 0, TimeSpan.Zero); var rt = RichToken.Create(payload, 0, issued); var str = rt.ToString(); var ok = RichToken.TryParse(str, out RichToken rt2); Assert.True(ok); Assert.True(rt.Equals(rt2)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var str = reader.Value as string; if (string.IsNullOrEmpty(str) || str == "null") { return(objectType.IsNullable() ? (RichToken?)null : RichToken.Empty); } if (RichToken.TryParse(str, out RichToken token)) { return(token); } var msg = $"Deserialization by calling Fabric.Core.ValueTypes.RichToken.TryParse(\"{str}\") has failed."; throw new JsonSerializationException(msg); }