| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.Common.Serialization; |
| | | 3 | | using Elsa.Workflows.Serialization.Converters; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Serialization.Serializers; |
| | | 6 | | |
| | | 7 | | /// <inheritdoc cref="IActivitySerializer" /> |
| | 114 | 8 | | public class JsonActivitySerializer(IServiceProvider serviceProvider) : ConfigurableSerializer(serviceProvider), IActivi |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public string Serialize(IActivity activity) |
| | | 12 | | { |
| | 652 | 13 | | var options = GetOptionsInternal(); |
| | 652 | 14 | | return JsonSerializer.Serialize(activity, activity.GetType(), options); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public string Serialize(object value) |
| | | 19 | | { |
| | 0 | 20 | | var options = GetOptionsInternal(); |
| | 0 | 21 | | return JsonSerializer.Serialize(value, options); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | 8 | 25 | | public IActivity Deserialize(string serializedActivity) => JsonSerializer.Deserialize<IActivity>(serializedActivity, |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 0 | 28 | | public object Deserialize(string serializedValue, Type type) => JsonSerializer.Deserialize(serializedValue, type, Ge |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | 1061 | 31 | | public T Deserialize<T>(string serializedValue) => JsonSerializer.Deserialize<T>(serializedValue, GetOptions())!; |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | protected override void AddConverters(JsonSerializerOptions options) |
| | | 35 | | { |
| | 652 | 36 | | options.Converters.Add(CreateInstance<TypeJsonConverter>()); |
| | 652 | 37 | | options.Converters.Add(CreateInstance<InputJsonConverterFactory>()); |
| | 652 | 38 | | options.Converters.Add(CreateInstance<OutputJsonConverterFactory>()); |
| | 652 | 39 | | options.Converters.Add(CreateInstance<ExpressionJsonConverterFactory>()); |
| | 652 | 40 | | options.Converters.Add(CreateInstance<FuncExpressionValueConverter>()); |
| | 652 | 41 | | } |
| | | 42 | | } |