elsa-core/src/modules/Elsa.Common/Contracts/IJsonSerializer.cs
Sipke Schoorstra 1e6aee4bba
Refactor serializer options usage and enhance caching in workflow serialization (#5275)
* Refactor serializer options usage and enhance caching in workflow serialization

This update refactors multiple classes dealing with JSON serialization. The usage of serializer options now includes a caching mechanism to avoid unnecessary recomputation. 'CreateOptions' method is replaced by a 'GetOptions' method that considers cached options. Classes are adjusted to clone options when necessary, ensuring a fresh and accurate context each time.

* Refactor serializer options in workflow serialization

This commit refactors how options are handled for JSON serializers in Elsa's workflow modules. JSON serializer options are now handled more efficiently, by directly using the provided options in `JsonIgnoreCompositeRootConverter` and setting up internal serializer options in `ObjectConverter`. Unnecessary methods related to the cloning of serializer options have been removed.
2024-04-25 11:42:48 +02:00

44 lines
1.2 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
namespace Elsa.Common.Contracts;
/// <summary>
/// Provides JSON serialization services.
/// </summary>
public interface IJsonSerializer
{
/// <summary>
/// Returns the serializer options.
/// </summary>
JsonSerializerOptions GetOptions();
/// <summary>
/// Applies the specified options.
/// </summary>
void ApplyOptions(JsonSerializerOptions options);
/// <summary>
/// Serializes the specified value.
/// </summary>
[RequiresUnreferencedCode("The type is not known at compile time.")]
string Serialize(object value);
/// <summary>
/// Serializes the specified value.
/// </summary>
[RequiresUnreferencedCode("The type is not known at compile time.")]
string Serialize(object value, Type type);
/// <summary>
/// Deserializes the specified JSON.
/// </summary>
[RequiresUnreferencedCode("The type is not known at compile time.")]
object Deserialize(string json);
/// <summary>
/// Deserializes the specified JSON.
/// </summary>
[RequiresUnreferencedCode("The type is not known at compile time.")]
object Deserialize(string json, Type type);
}