| | | 1 | | using System.Text.Json; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Http.Serialization; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A custom JSON converter for <see cref="HttpStatusCodeCase"/> objects when serializing workflow states. |
| | | 8 | | /// </summary> |
| | | 9 | | public class HttpStatusCodeCaseForWorkflowInstanceConverter : JsonConverter<HttpStatusCodeCase> |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | public override HttpStatusCodeCase Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options |
| | | 13 | | { |
| | 0 | 14 | | throw new NotImplementedException(); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public override void Write(Utf8JsonWriter writer, HttpStatusCodeCase value, JsonSerializerOptions options) |
| | | 19 | | { |
| | 0 | 20 | | var properties = value.GetType().GetProperties(); |
| | | 21 | | |
| | 0 | 22 | | writer.WriteStartObject(); |
| | | 23 | | |
| | 0 | 24 | | foreach (var prop in properties) |
| | | 25 | | { |
| | | 26 | | // Don't serialize the Activity property. |
| | 0 | 27 | | if (prop.Name != nameof(HttpStatusCodeCase.Activity)) |
| | | 28 | | { |
| | 0 | 29 | | var propValue = prop.GetValue(value); |
| | 0 | 30 | | writer.WritePropertyName(prop.Name); |
| | 0 | 31 | | JsonSerializer.Serialize(writer, propValue, prop.PropertyType, options); |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | writer.WriteEndObject(); |
| | 0 | 36 | | } |
| | | 37 | | } |