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
optionsJsonSerializerOptionsJson 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
contextJsonSerializerContextJson 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
SerializerType
Gets the value written in the SerializerType tag of the current Activity.
protected override string SerializerType { get; }
Property Value
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
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
databyte[]The bytes of the ZIP archive.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
valueTThe value to serialize.
Returns
- byte[]
The serialized bytes.
Type Parameters
TThe type of the value.