Class JsonLdSerializer
- Namespace
- ActivityPub.Types.Conversion
- Assembly
- ActivityPub.Types.dll
Default implementation of IJsonLdSerializer.
public class JsonLdSerializer : IJsonLdSerializer
- Inheritance
-
JsonLdSerializer
- Implements
- Inherited Members
Constructors
JsonLdSerializer(IOptions<JsonLdSerializerOptions>, TypeMapConverter, ASTypeConverter, LinkableConverter, ListableConverter, ListableReadOnlyConverter)
Constructs a new instance of JsonLdSerializer from the provided services. This is meant to be called implicitly by a DI container, but can be used directly for testing or advanced use cases.
public JsonLdSerializer(IOptions<JsonLdSerializerOptions> serializerOptions, TypeMapConverter typeMapConverter, ASTypeConverter asTypeConverter, LinkableConverter linkableConverter, ListableConverter listableConverter, ListableReadOnlyConverter listableReadOnlyConverter)
Parameters
serializerOptionsIOptions<JsonLdSerializerOptions>typeMapConverterTypeMapConverterasTypeConverterASTypeConverterlinkableConverterLinkableConverterlistableConverterListableConverterlistableReadOnlyConverterListableReadOnlyConverter
Properties
SerializerOptions
Options in use by this instance. Will become read-only after first use.
public JsonSerializerOptions SerializerOptions { get; }
Property Value
Methods
Deserialize(Stream, Type)
Reads the UTF-8 encoded text representing a single JSON value into a returnType.
The Stream will be read to completion.
public object? Deserialize(Stream stream, Type type)
Parameters
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
utf8JsonorreturnTypeis null.- JsonException
The JSON is invalid, the
returnTypeis not compatible with the JSON, or there is remaining data in the Stream.- NotSupportedException
There is no compatible JsonConverter for
returnTypeor its serializable members.
Deserialize(ReadOnlySpan<byte>, Type)
Parses the UTF-8 encoded text representing a single JSON value into an instance of a specified type.
public object? Deserialize(ReadOnlySpan<byte> json, Type type)
Parameters
jsonReadOnlySpan<byte>typeType
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
returnTypeis null.- JsonException
The JSON is invalid.
-or-
returnTypeis not compatible with the JSON.-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible
for returnTypeor its serializable members.
Deserialize(ReadOnlySpan<char>, Type)
Parses the text representing a single JSON value into an instance of a specified type.
public object? Deserialize(ReadOnlySpan<char> json, Type type)
Parameters
jsonReadOnlySpan<char>The JSON text to parse.
typeType
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
returnTypeis null.- JsonException
The JSON is invalid.
-or-
returnTypeis not compatible with the JSON.-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible JsonConverter for
returnTypeor its serializable members.
Deserialize(string, Type)
Parses the text representing a single JSON value into an instance of a specified type.
public object? Deserialize(string json, Type type)
Parameters
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
jsonorreturnTypeis null.- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the string beyond a single JSON value.
- NotSupportedException
There is no compatible
for returnTypeor its serializable members.
Deserialize(JsonDocument, Type)
Converts the JsonDocument representing a single JSON value into a returnType.
public object? Deserialize(JsonDocument document, Type type)
Parameters
documentJsonDocumentThe JsonDocument to convert.
typeType
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
documentorreturnTypeis null.- JsonException
returnTypeis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnTypeor its serializable members.
Deserialize(JsonElement, Type)
Converts the JsonElement representing a single JSON value into a returnType.
public object? Deserialize(JsonElement element, Type type)
Parameters
elementJsonElementThe JsonElement to convert.
typeType
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
returnTypeis null.- JsonException
returnTypeis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnTypeor its serializable members.
Deserialize(JsonNode, Type)
Converts the JsonNode representing a single JSON value into a returnType.
public object? Deserialize(JsonNode node, Type type)
Parameters
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- JsonException
returnTypeis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnTypeor its serializable members.
Deserialize(ref Utf8JsonReader, Type)
Reads one JSON value (including objects or arrays) from the provided reader and converts it into an instance of a specified type.
public object? Deserialize(ref Utf8JsonReader reader, Type type)
Parameters
readerUtf8JsonReaderThe reader to read the JSON from.
typeType
Returns
- object
A
returnTyperepresentation of the JSON value.
Exceptions
- ArgumentNullException
returnTypeis null.- JsonException
The JSON is invalid.
-or-
returnTypeis not compatible with the JSON.-or-
A value could not be read from the reader.
- ArgumentException
readeris using unsupported options.- NotSupportedException
There is no compatible
for returnTypeor its serializable members.
DeserializeAsync(Stream, Type, CancellationToken)
Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a specified type. The stream will be read to completion.
public ValueTask<object?> DeserializeAsync(Stream json, Type type, CancellationToken cancellationToken = default)
Parameters
jsonStreamtypeTypecancellationTokenCancellationTokenA cancellation token that may be used to cancel the read operation.
Returns
Exceptions
- ArgumentNullException
utf8JsonorreturnTypeis null.- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the stream.
- NotSupportedException
There is no compatible
for returnTypeor its serializable members.
DeserializeAsyncEnumerable<T>(Stream, CancellationToken)
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level JSON arrays in a streaming manner.
public IAsyncEnumerable<T?> DeserializeAsyncEnumerable<T>(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamcancellationTokenCancellationTokenThe CancellationToken which may be used to cancel the read operation.
Returns
- IAsyncEnumerable<T>
An IAsyncEnumerable<T> representation of the provided JSON array.
Type Parameters
T
Exceptions
- ArgumentNullException
utf8Jsonis null.
DeserializeAsync<T>(Stream, CancellationToken)
Asynchronously reads the UTF-8 encoded text representing a single JSON value into an instance of a type specified by a generic type parameter. The stream will be read to completion.
public ValueTask<T?> DeserializeAsync<T>(Stream json, CancellationToken cancellationToken = default)
Parameters
jsonStreamcancellationTokenCancellationTokenA token that may be used to cancel the read operation.
Returns
- ValueTask<T>
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the stream.
- NotSupportedException
There is no compatible
for TValueor its serializable members.- ArgumentNullException
utf8Jsonis null.
Deserialize<T>(Stream)
Reads the UTF-8 encoded text representing a single JSON value into a TValue.
The Stream will be read to completion.
public T? Deserialize<T>(Stream stream)
Parameters
streamStream
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
utf8Jsonis null.- JsonException
The JSON is invalid,
TValueis not compatible with the JSON, or there is remaining data in the Stream.- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Deserialize<T>(ReadOnlySpan<byte>)
Parses the UTF-8 encoded text representing a single JSON value into an instance of the type specified by a generic type parameter.
public T? Deserialize<T>(ReadOnlySpan<byte> json)
Parameters
jsonReadOnlySpan<byte>
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible
for TValueor its serializable members.
Deserialize<T>(ReadOnlySpan<char>)
Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.
public T? Deserialize<T>(ReadOnlySpan<char> json)
Parameters
jsonReadOnlySpan<char>The JSON text to parse.
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Deserialize<T>(string)
Parses the text representing a single JSON value into an instance of the type specified by a generic type parameter.
public T? Deserialize<T>(string json)
Parameters
jsonstringThe JSON text to parse.
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
jsonis null.- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
There is remaining data in the string beyond a single JSON value.
- NotSupportedException
There is no compatible
for TValueor its serializable members.
Deserialize<T>(JsonDocument)
Converts the JsonDocument representing a single JSON value into a TValue.
public T? Deserialize<T>(JsonDocument document)
Parameters
documentJsonDocumentThe JsonDocument to convert.
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
documentis null.- JsonException
TValueis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Deserialize<T>(JsonElement)
Converts the JsonElement representing a single JSON value into a TValue.
public T? Deserialize<T>(JsonElement element)
Parameters
elementJsonElementThe JsonElement to convert.
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
TValueis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Deserialize<T>(JsonNode)
Converts the JsonNode representing a single JSON value into a TValue.
public T? Deserialize<T>(JsonNode node)
Parameters
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
TValueis not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Deserialize<T>(ref Utf8JsonReader)
Reads one JSON value (including objects or arrays) from the provided reader into an instance of the type specified by a generic type parameter.
public T? Deserialize<T>(ref Utf8JsonReader reader)
Parameters
readerUtf8JsonReaderThe reader to read the JSON from.
Returns
- T
A
TValuerepresentation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValueis not compatible with the JSON.-or-
A value could not be read from the reader.
- ArgumentException
readeruses unsupported options.- NotSupportedException
There is no compatible
for TValueor its serializable members.
Serialize(Stream, object?, Type)
Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.
public void Serialize(Stream stream, object? value, Type type)
Parameters
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
utf8JsonorinputTypeis null.- NotSupportedException
There is no compatible JsonConverter for
inputTypeor its serializable members.
Serialize(object?, Type)
Converts the value of a specified type into a JSON string.
public string Serialize(object? value, Type type)
Parameters
Returns
- string
The JSON string representation of the value.
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
inputTypeis null.- NotSupportedException
There is no compatible
for inputTypeor its serializable members.
Serialize(Utf8JsonWriter, object?, Type)
Writes the JSON representation of the specified type to the provided writer.
public void Serialize(Utf8JsonWriter writer, object? value, Type type)
Parameters
writerUtf8JsonWriterThe JSON writer to write to.
valueobjectThe value to convert and write.
typeType
Exceptions
- ArgumentException
inputTypeis not compatible withvalue- ArgumentNullException
writerorinputTypeis null.- NotSupportedException
There is no compatible
for inputTypeor its serializable members.
SerializeToDocument(object?, Type)
Converts the provided value into a JsonDocument.
public JsonDocument SerializeToDocument(object? value, Type type)
Parameters
Returns
- JsonDocument
A JsonDocument representation of the value.
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
inputTypeis null.- NotSupportedException
There is no compatible JsonConverter for
inputTypeor its serializable members.
SerializeToDocument<T>(T?)
Converts the provided value into a JsonDocument.
public JsonDocument SerializeToDocument<T>(T? value)
Parameters
valueTThe value to convert.
Returns
- JsonDocument
A JsonDocument representation of the JSON value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
SerializeToElement(object?, Type)
Converts the provided value into a JsonDocument.
public JsonElement SerializeToElement(object? value, Type type)
Parameters
Returns
- JsonElement
A JsonDocument representation of the value.
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
inputTypeis null.- NotSupportedException
There is no compatible JsonConverter for
inputTypeor its serializable members.
SerializeToElement<T>(T?)
Converts the provided value into a JsonDocument.
public JsonElement SerializeToElement<T>(T? value)
Parameters
valueTThe value to convert.
Returns
- JsonElement
A JsonDocument representation of the JSON value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
SerializeToNode(object?, Type)
Converts the provided value into a JsonNode.
public JsonNode? SerializeToNode(object? value, Type type)
Parameters
Returns
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
inputTypeis null.- NotSupportedException
There is no compatible JsonConverter for
inputTypeor its serializable members.
SerializeToNode<T>(T?)
Converts the provided value into a JsonNode.
public JsonNode? SerializeToNode<T>(T? value)
Parameters
valueTThe value to convert.
Returns
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
SerializeToUtf8Bytes(object?, Type)
Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.
public byte[] SerializeToUtf8Bytes(object? value, Type type)
Parameters
Returns
- byte[]
A JSON string representation of the value, encoded as UTF-8 bytes.
Exceptions
- ArgumentException
inputTypeis not compatible withvalue.- ArgumentNullException
inputTypeis null.- NotSupportedException
There is no compatible
for inputTypeor its serializable members.
SerializeToUtf8Bytes<T>(T?)
Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.
public byte[] SerializeToUtf8Bytes<T>(T? value)
Parameters
valueTThe value to convert.
Returns
- byte[]
A JSON string representation of the value, encoded as UTF-8 bytes.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible
for TValueor its serializable members.
Serialize<T>(Stream, T?)
Converts the provided value to UTF-8 encoded JSON text and write it to the Stream.
public void Serialize<T>(Stream stream, T? value)
Parameters
streamStreamvalueTThe value to convert.
Type Parameters
T
Exceptions
- ArgumentNullException
utf8Jsonis null.- NotSupportedException
There is no compatible JsonConverter for
TValueor its serializable members.
Serialize<T>(Utf8JsonWriter, T?)
Writes the JSON representation of a type specified by a generic type parameter to the provided writer.
public void Serialize<T>(Utf8JsonWriter writer, T? value)
Parameters
writerUtf8JsonWriterA JSON writer to write to.
valueTThe value to convert and write.
Type Parameters
T
Exceptions
- ArgumentNullException
writeris null.- NotSupportedException
There is no compatible
for TValueor its serializable members.
Serialize<T>(T?)
Converts the value of a type specified by a generic type parameter into a JSON string.
public string Serialize<T>(T? value)
Parameters
valueTThe value to convert.
Returns
- string
A JSON string representation of the value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible
for TValueor its serializable members.