/// <inheritdoc /> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var str = reader.Value.ToString(); if (str == null) { return(null); } return((EventId)EventId.Parse(str)); }
private Event DeserializeEvent(string payload) { if (payload == null) { return(null); } var reader = new JsonTextReader(new StringReader(payload)) { DateParseHandling = DateParseHandling.None }; var deserializer = _serializationRegistry.GetDeserializer(payload); if (deserializer == null) { return(null); } var e = deserializer.Create(); var currentProperty = string.Empty; while (reader.Read()) { if (reader.Value == null) { continue; } switch (reader.TokenType) { case JsonToken.PropertyName: currentProperty = reader.Value.ToString(); break; case JsonToken.String when currentProperty == nameof(Message.MessageId): e.MessageId = Guid.Parse(reader.Value.ToString()); break; case JsonToken.String when currentProperty == nameof(Message.AncestorId): e.AncestorId = Guid.Parse(reader.Value.ToString()); break; case JsonToken.String when currentProperty == nameof(Message.CorrelationId): e.CorrelationId = reader.Value.ToString(); break; case JsonToken.String when currentProperty == nameof(Message.Timestamp): e.Timestamp = Time.FromExtendedIso((string)reader.Value); break; case JsonToken.Date when currentProperty == nameof(Message.Timestamp): e.Timestamp = Time.FromExtendedIso(reader.Value.ToString()); break; case JsonToken.String when currentProperty == nameof(Message.LocalId): e.LocalId = EventId.Parse((string)reader.Value); break; case JsonToken.String when currentProperty == nameof(Message.OriginId): e.OriginId = EventId.Parse((string)reader.Value); break; case JsonToken.Integer when currentProperty == nameof(EventMetadata.Version): e.Version = (int)(long)reader.Value; break; case JsonToken.String when currentProperty == nameof(EventMetadata.MessageType): e.MessageType = (string)reader.Value; break; case JsonToken.String when currentProperty == nameof(EventMetadata.Hash): e.Hash = (string)reader.Value; break; case JsonToken.String when currentProperty == nameof(Event.CommandId): e.CommandId = Guid.Parse(reader.Value.ToString()); break; case JsonToken.String when currentProperty == nameof(Event.Stream): e.Stream = (string)reader.Value; break; case JsonToken.String when currentProperty == nameof(Event.Timeline): e.Timeline = (string)reader.Value; break; } deserializer.Switch(reader, currentProperty, e); } return(e); }