Table of Contents

Interface IJsonSerializer

Namespace
Vonage.Common
Assembly
Vonage.dll

Defines a contract for JSON serialization and deserialization with Result-based error handling.

public interface IJsonSerializer

Remarks

Implementations use Result<T> for deserialization to handle failures gracefully without exceptions.

See JsonSerializer for the default implementation.

Methods

DeserializeObject<T>(string)

Deserializes a JSON string to the specified type.

Result<T> DeserializeObject<T>(string serializedValue)

Parameters

serializedValue string

The JSON string to deserialize.

Returns

Result<T>

A Result<T> containing the deserialized object on success, or a DeserializationFailure on failure.

Type Parameters

T

The target type to deserialize to.

Examples

var result = serializer.DeserializeObject<User>("{\"name\":\"John\"}");
result.Match(
    user => Console.WriteLine(user.Name),
    failure => Console.WriteLine("Deserialization failed")
);

SerializeObject<T>(T)

Serializes an object to a JSON string.

string SerializeObject<T>(T value)

Parameters

value T

The object to serialize.

Returns

string

The JSON string representation of the object.

Type Parameters

T

The type of the object to serialize.

Examples

var json = serializer.SerializeObject(new User { Name = "John" });