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
serializerOptions
IOptions<JsonLdSerializerOptions>typeMapConverter
TypeMapConverterasTypeConverter
ASTypeConverterlinkableConverter
LinkableConverterlistableConverter
ListableConverterlistableReadOnlyConverter
ListableReadOnlyConverter
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
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
utf8Json
orreturnType
is null.- JsonException
The JSON is invalid, the
returnType
is not compatible with the JSON, or there is remaining data in the Stream.- NotSupportedException
There is no compatible JsonConverter for
returnType
or 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
json
ReadOnlySpan<byte>type
Type
Returns
- object
A
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
returnType
is null.- JsonException
The JSON is invalid.
-or-
returnType
is not compatible with the JSON.-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible
for returnType
or 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
json
ReadOnlySpan<char>The JSON text to parse.
type
Type
Returns
- object
A
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
returnType
is null.- JsonException
The JSON is invalid.
-or-
returnType
is 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
returnType
or 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
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
json
orreturnType
is null.- JsonException
The JSON is invalid.
-or-
TValue
is not compatible with the JSON.-or-
There is remaining data in the string beyond a single JSON value.
- NotSupportedException
There is no compatible
for returnType
or 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
document
JsonDocumentThe JsonDocument to convert.
type
Type
Returns
- object
A
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
document
orreturnType
is null.- JsonException
returnType
is not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnType
or 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
element
JsonElementThe JsonElement to convert.
type
Type
Returns
- object
A
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
returnType
is null.- JsonException
returnType
is not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnType
or 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
returnType
representation of the JSON value.
Exceptions
- JsonException
returnType
is not compatible with the JSON.- NotSupportedException
There is no compatible JsonConverter for
returnType
or 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
reader
Utf8JsonReaderThe reader to read the JSON from.
type
Type
Returns
- object
A
returnType
representation of the JSON value.
Exceptions
- ArgumentNullException
returnType
is null.- JsonException
The JSON is invalid.
-or-
returnType
is not compatible with the JSON.-or-
A value could not be read from the reader.
- ArgumentException
reader
is using unsupported options.- NotSupportedException
There is no compatible
for returnType
or 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
json
Streamtype
TypecancellationToken
CancellationTokenA cancellation token that may be used to cancel the read operation.
Returns
Exceptions
- ArgumentNullException
utf8Json
orreturnType
is null.- JsonException
The JSON is invalid.
-or-
TValue
is not compatible with the JSON.-or-
There is remaining data in the stream.
- NotSupportedException
There is no compatible
for returnType
or 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
stream
StreamcancellationToken
CancellationTokenThe 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
utf8Json
is 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
json
StreamcancellationToken
CancellationTokenA token that may be used to cancel the read operation.
Returns
- ValueTask<T>
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValue is not compatible with the JSON.
-or-
There is remaining data in the stream.
- NotSupportedException
There is no compatible
for TValue or its serializable members. - ArgumentNullException
utf8Json
is 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
stream
Stream
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
utf8Json
is null.- JsonException
The JSON is invalid, TValue is not compatible with the JSON, or there is remaining data in the Stream.
- NotSupportedException
There is no compatible JsonConverter for TValue or 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
json
ReadOnlySpan<byte>
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValue is not compatible with the JSON.
-or-
There is remaining data in the span beyond a single JSON value.
- NotSupportedException
There is no compatible
for TValue or 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
json
ReadOnlySpan<char>The JSON text to parse.
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValue is 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 TValue or 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
json
stringThe JSON text to parse.
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
json
is null.- JsonException
The JSON is invalid.
-or-
TValue is not compatible with the JSON.
-or-
There is remaining data in the string beyond a single JSON value.
- NotSupportedException
There is no compatible
for TValue or its serializable members.
Deserialize<T>(JsonDocument)
Converts the JsonDocument representing a single JSON value into a TValue.
public T? Deserialize<T>(JsonDocument document)
Parameters
document
JsonDocumentThe JsonDocument to convert.
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- ArgumentNullException
document
is null.- JsonException
TValue is not compatible with the JSON.
- NotSupportedException
There is no compatible JsonConverter for TValue or its serializable members.
Deserialize<T>(JsonElement)
Converts the JsonElement representing a single JSON value into a TValue.
public T? Deserialize<T>(JsonElement element)
Parameters
element
JsonElementThe JsonElement to convert.
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
TValue is not compatible with the JSON.
- NotSupportedException
There is no compatible JsonConverter for TValue or 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 TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
TValue is not compatible with the JSON.
- NotSupportedException
There is no compatible JsonConverter for TValue or 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
reader
Utf8JsonReaderThe reader to read the JSON from.
Returns
- T
A TValue representation of the JSON value.
Type Parameters
T
Exceptions
- JsonException
The JSON is invalid.
-or-
TValue is not compatible with the JSON.
-or-
A value could not be read from the reader.
- ArgumentException
reader
uses unsupported options.- NotSupportedException
There is no compatible
for TValue or 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
inputType
is not compatible withvalue
.- ArgumentNullException
utf8Json
orinputType
is null.- NotSupportedException
There is no compatible JsonConverter for
inputType
or 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
inputType
is not compatible withvalue
.- ArgumentNullException
inputType
is null.- NotSupportedException
There is no compatible
for inputType
or 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
writer
Utf8JsonWriterThe JSON writer to write to.
value
objectThe value to convert and write.
type
Type
Exceptions
- ArgumentException
inputType
is not compatible withvalue
- ArgumentNullException
writer
orinputType
is null.- NotSupportedException
There is no compatible
for inputType
or 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
inputType
is not compatible withvalue
.- ArgumentNullException
inputType
is null.- NotSupportedException
There is no compatible JsonConverter for
inputType
or its serializable members.
SerializeToDocument<T>(T?)
Converts the provided value into a JsonDocument.
public JsonDocument SerializeToDocument<T>(T? value)
Parameters
value
TThe value to convert.
Returns
- JsonDocument
A JsonDocument representation of the JSON value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for TValue or 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
inputType
is not compatible withvalue
.- ArgumentNullException
inputType
is null.- NotSupportedException
There is no compatible JsonConverter for
inputType
or its serializable members.
SerializeToElement<T>(T?)
Converts the provided value into a JsonDocument.
public JsonElement SerializeToElement<T>(T? value)
Parameters
value
TThe value to convert.
Returns
- JsonElement
A JsonDocument representation of the JSON value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for TValue or its serializable members.
SerializeToNode(object?, Type)
Converts the provided value into a JsonNode.
public JsonNode? SerializeToNode(object? value, Type type)
Parameters
Returns
Exceptions
- ArgumentException
inputType
is not compatible withvalue
.- ArgumentNullException
inputType
is null.- NotSupportedException
There is no compatible JsonConverter for
inputType
or its serializable members.
SerializeToNode<T>(T?)
Converts the provided value into a JsonNode.
public JsonNode? SerializeToNode<T>(T? value)
Parameters
value
TThe value to convert.
Returns
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible JsonConverter for TValue or 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
inputType
is not compatible withvalue
.- ArgumentNullException
inputType
is null.- NotSupportedException
There is no compatible
for inputType
or 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
value
TThe 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 TValue or 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
stream
Streamvalue
TThe value to convert.
Type Parameters
T
Exceptions
- ArgumentNullException
utf8Json
is null.- NotSupportedException
There is no compatible JsonConverter for TValue or 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
writer
Utf8JsonWriterA JSON writer to write to.
value
TThe value to convert and write.
Type Parameters
T
Exceptions
- ArgumentNullException
writer
is null.- NotSupportedException
There is no compatible
for TValue or 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
value
TThe value to convert.
Returns
- string
A JSON string representation of the value.
Type Parameters
T
Exceptions
- NotSupportedException
There is no compatible
for TValue or its serializable members.