/// <typeparamref name="TValue"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
[return: MaybeNull]
public static TValue Deserialize<TValue>(ReadOnlySpan<byte> utf8Json, JsonSerializerOptions? options = null)
{
/// <param name="returnType">The type of the object to convert to and return.</param>
/// <param name="options">Options to control the behavior during parsing.</param>
/// <exception cref="System.ArgumentNullException">
- /// Thrown if <paramref name="returnType"/> is null.
+ /// <paramref name="returnType"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// <paramref name="returnType"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="returnType"/> or its serializable members.
+ /// </exception>
public static object? Deserialize(ReadOnlySpan<byte> utf8Json, Type returnType, JsonSerializerOptions? options = null)
{
if (returnType == null)
/// <param name="cancellationToken">
/// The <see cref="System.Threading.CancellationToken"/> which may be used to cancel the read operation.
/// </param>
+ /// <exception cref="System.ArgumentNullException">
+ /// <paramref name="utf8Json"/>is <see langword="null"/>.
+ /// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// <typeparamref name="TValue"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
public static ValueTask<TValue> DeserializeAsync<TValue>(
Stream utf8Json,
JsonSerializerOptions? options = null,
/// The <see cref="System.Threading.CancellationToken"/> which may be used to cancel the read operation.
/// </param>
/// <exception cref="System.ArgumentNullException">
- /// Thrown if <paramref name="utf8Json"/> or <paramref name="returnType"/> is null.
+ /// <paramref name="utf8Json"/> or <paramref name="returnType"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// the <paramref name="returnType"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="returnType"/> or its serializable members.
+ /// </exception>
public static ValueTask<object?> DeserializeAsync(
Stream utf8Json,
Type returnType,
/// <param name="json">JSON text to parse.</param>
/// <param name="options">Options to control the behavior during parsing.</param>
/// <exception cref="System.ArgumentNullException">
- /// Thrown if <paramref name="json"/> is null.
+ /// <paramref name="json"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// <typeparamref name="TValue"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
/// <remarks>Using a <see cref="string"/> is not as efficient as using the
/// UTF-8 methods since the implementation natively uses UTF-8.
/// </remarks>
/// <param name="returnType">The type of the object to convert to and return.</param>
/// <param name="options">Options to control the behavior during parsing.</param>
/// <exception cref="System.ArgumentNullException">
- /// Thrown if <paramref name="json"/> or <paramref name="returnType"/> is null.
+ /// <paramref name="json"/> or <paramref name="returnType"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// the <paramref name="returnType"/> is not compatible with the JSON,
/// or when there is remaining data in the Stream.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="returnType"/> or its serializable members.
+ /// </exception>
/// <remarks>Using a <see cref="string"/> is not as efficient as using the
/// UTF-8 methods since the implementation natively uses UTF-8.
/// </remarks>
/// <exception cref="ArgumentException">
/// <paramref name="reader"/> is using unsupported options.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
/// <remarks>
/// <para>
/// If the <see cref="Utf8JsonReader.TokenType"/> property of <paramref name="reader"/>
/// <param name="returnType">The type of the object to convert to and return.</param>
/// <param name="options">Options to control the serializer behavior during reading.</param>
/// <exception cref="ArgumentNullException">
- /// Thrown if <paramref name="returnType"/> is null.
+ /// <paramref name="returnType"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="JsonException">
/// Thrown when the JSON is invalid,
/// <exception cref="ArgumentException">
/// <paramref name="reader"/> is using unsupported options.
/// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="returnType"/> or its serializable members.
+ /// </exception>
/// <remarks>
/// <para>
/// If the <see cref="Utf8JsonReader.TokenType"/> property of <paramref name="reader"/>
/// <returns>A UTF-8 representation of the value.</returns>
/// <param name="value">The value to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, JsonSerializerOptions? options = null)
{
return WriteCoreBytes<TValue>(value, typeof(TValue), options);
/// <param name="value">The value to convert.</param>
/// <param name="inputType">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="inputType"/> is not compatible with <paramref name="value"/>.
+ /// </exception>
+ /// <exception cref="System.ArgumentNullException">
+ /// <paramref name="inputType"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="inputType"/> or its serializable members.
+ /// </exception>
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, JsonSerializerOptions? options = null)
{
if (inputType == null)
/// <param name="value">The value to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> which may be used to cancel the write operation.</param>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="utf8Json"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
public static Task SerializeAsync<TValue>(Stream utf8Json, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
{
if (utf8Json == null)
/// <param name="inputType">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
/// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> which may be used to cancel the write operation.</param>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="inputType"/> is not compatible with <paramref name="value"/>.
+ /// </exception>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="utf8Json"/> or <paramref name="inputType"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="inputType"/> or its serializable members.
+ /// </exception>
public static Task SerializeAsync(Stream utf8Json, object? value, Type inputType, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
{
if (utf8Json == null)
/// <returns>A <see cref="string"/> representation of the value.</returns>
/// <param name="value">The value to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
+ /// </exception>
/// <remarks>Using a <see cref="string"/> is not as efficient as using UTF-8
/// encoding since the implementation internally uses UTF-8. See also <see cref="SerializeToUtf8Bytes"/>
/// and <see cref="SerializeAsync"/>.
/// <param name="value">The value to convert.</param>
/// <param name="inputType">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the conversion behavior.</param>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="inputType"/> is not compatible with <paramref name="value"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="inputType"/> or its serializable members.
+ /// </exception>
/// <remarks>Using a <see cref="string"/> is not as efficient as using UTF-8
/// encoding since the implementation internally uses UTF-8. See also <see cref="SerializeToUtf8Bytes"/>
/// and <see cref="SerializeAsync"/>.
/// <param name="value">The value to convert and write.</param>
/// <param name="options">Options to control the behavior.</param>
/// <exception cref="ArgumentNullException">
- /// <paramref name="writer"/> is null.
+ /// <paramref name="writer"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <typeparamref name="TValue"/> or its serializable members.
/// </exception>
public static void Serialize<TValue>(Utf8JsonWriter writer, TValue value, JsonSerializerOptions? options = null)
{
/// <param name="value">The value to convert and write.</param>
/// <param name="inputType">The type of the <paramref name="value"/> to convert.</param>
/// <param name="options">Options to control the behavior.</param>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="inputType"/> is not compatible with <paramref name="value"/>.
+ /// </exception>
/// <exception cref="ArgumentNullException">
- /// <paramref name="writer"/> is null.
+ /// <paramref name="writer"/> or <paramref name="inputType"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="inputType"/> or its serializable members.
/// </exception>
public static void Serialize(Utf8JsonWriter writer, object? value, Type inputType, JsonSerializerOptions? options = null)
{
/// <returns>
/// The converter for the given type.
/// </returns>
+ /// <exception cref="InvalidOperationException">
+ /// The configured <see cref="JsonConverter"/> for <paramref name="typeToConvert"/> returned an invalid converter.
+ /// </exception>
+ /// <exception cref="NotSupportedException">
+ /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
+ /// for <paramref name="typeToConvert"/> or its serializable members.
+ /// </exception>
public JsonConverter GetConverter(Type typeToConvert)
{
if (_converters.TryGetValue(typeToConvert, out JsonConverter? converter))