Table of Contents

Class JsonZipSerialization

Namespace
Arc4u.Serializer
Assembly
Arc4u.Serializer.JSon.dll

Implements object serialization with JSON stored as a single entry (see EntryName) of a ZIP archive.

public class JsonZipSerialization : JsonCompressedStreamSerializationBase, IObjectSerialization
Inheritance
JsonZipSerialization
Implements
Inherited Members

Constructors

JsonZipSerialization()

Construct an instance with default options

[RequiresUnreferencedCode("This constructor is not suitable for AOT. Use the constructor with JsonSerializerContext for AOT compatibility.")]
public JsonZipSerialization()

JsonZipSerialization(JsonSerializerOptions)

Construct an instance, with specific serializer options

[RequiresUnreferencedCode("This constructor is not suitable for AOT. Use the constructor with JsonSerializerContext for AOT compatibility.")]
public JsonZipSerialization(JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

Json serializer optios. Default is to use the default options

JsonZipSerialization(JsonSerializerContext)

Construct an instance with a serialization context. This is used for source generation, implemented in .NET 6 or later (https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-6-0)

[RequiresUnreferencedCode("This constructor is not suitable for AOT. Use the constructor with JsonSerializerContext for AOT compatibility.")]
public JsonZipSerialization(JsonSerializerContext context)

Parameters

context JsonSerializerContext

Json context for source generation.

Properties

EntryName

The name of the entry in the .ZIP file. Default is "content".

protected virtual string EntryName { get; }

Property Value

string

SerializerType

Gets the value written in the SerializerType tag of the current Activity.

protected override string SerializerType { get; }

Property Value

string

Methods

Deserialize(byte[], Type)

Reads the JSON entry of the ZIP archive and deserializes it to the given type.

public object? Deserialize(byte[] data, Type objectType)

Parameters

data byte[]

The bytes of the ZIP archive.

objectType Type

The type of the object to create.

Returns

object

The deserialized object.

Exceptions

InvalidOperationException

The archive has no entry named EntryName.

Deserialize<T>(byte[])

Reads the JSON entry of the ZIP archive and deserializes it.

public T? Deserialize<T>(byte[] data)

Parameters

data byte[]

The bytes of the ZIP archive.

Returns

T

The deserialized value.

Type Parameters

T

The expected type of the value.

Exceptions

InvalidOperationException

The archive has no entry named EntryName.

Serialize<T>(T)

Serializes a value to bytes.

public byte[] Serialize<T>(T value)

Parameters

value T

The value to serialize.

Returns

byte[]

The serialized bytes.

Type Parameters

T

The type of the value.