JsonSerializer.SerializeToUtf8Bytes Method

Definition

Overloads

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.

SerializeToUtf8Bytes(Object, JsonTypeInfo)

Converts the provided value into a Byte array.

SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)

Converts the provided value into a Byte array.

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.

SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>)

Converts the provided value into a Byte array.

SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

Converts a value of the specified type into a JSON string, encoded as UTF-8 bytes.

C#
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static byte[] SerializeToUtf8Bytes(object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);

Parameters

value
Object

The value to convert.

inputType
Type

The type of the value to convert.

options
JsonSerializerOptions

Options to control the conversion behavior.

Returns

Byte[]

A JSON string representation of the value, encoded as UTF-8 bytes.

Exceptions

inputType is not compatible with value.

inputType is null.

There is no compatible JsonConverter for inputType or its serializable members.

Remarks

For more information, see How to serialize and deserialize JSON.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

SerializeToUtf8Bytes(Object, JsonTypeInfo)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

Converts the provided value into a Byte array.

C#
public static byte[] SerializeToUtf8Bytes(object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);

Parameters

value
Object

The value to convert.

jsonTypeInfo
JsonTypeInfo

Metadata about the type to convert.

Returns

Byte[]

A UTF-8 representation of the value.

Exceptions

jsonTypeInfo is null.

value does not match the type of jsonTypeInfo.

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

Converts the provided value into a Byte array.

C#
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);

Parameters

value
Object

The value to convert.

inputType
Type

The type of the value to convert.

context
JsonSerializerContext

A metadata provider for serializable types.

Returns

Byte[]

A UTF-8 representation of the value.

Exceptions

inputType is not compatible with value.

inputType is null.

There is no compatible JsonConverter for inputType or its serializable members.

The GetTypeInfo(Type) method of the provided context returns null for the type to convert.

Applies to

.NET 10 and other versions
Product Versions
.NET 6, 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

Converts the value of a type specified by a generic type parameter into a JSON string, encoded as UTF-8 bytes.

C#
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
C#
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.JsonSerializerOptions options = default);

Type Parameters

TValue

The type of the value.

Parameters

value
TValue

The value to convert.

options
JsonSerializerOptions

Options to control the conversion behavior.

Returns

Byte[]

A JSON string representation of the value, encoded as UTF-8 bytes.

Exceptions

There is no compatible JsonConverter for TValue or its serializable members.

Remarks

For more information, see How to serialize and deserialize JSON.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>)

Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs
Source:
JsonSerializer.Write.ByteArray.cs

Converts the provided value into a Byte array.

C#
public static byte[] SerializeToUtf8Bytes<TValue>(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);

Type Parameters

TValue

The type of the value to serialize.

Parameters

value
TValue

The value to convert.

jsonTypeInfo
JsonTypeInfo<TValue>

Metadata about the type to convert.

Returns

Byte[]

A UTF-8 representation of the value.

Exceptions

There is no compatible JsonConverter for TValue or its serializable members.

jsonTypeInfo is null.

Applies to

.NET 10 and other versions
Product Versions
.NET 6, 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)