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

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

public static byte[] SerializeToUtf8Bytes (object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes (object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);
static member SerializeToUtf8Bytes : obj * Type * System.Text.Json.JsonSerializerOptions -> byte[]
Public Shared Function SerializeToUtf8Bytes (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As Byte()
Public Function SerializeToUtf8Bytes (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As Byte()

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

SerializeToUtf8Bytes(Object, JsonTypeInfo)

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

Converts the provided value into a Byte array.

public:
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static byte[] SerializeToUtf8Bytes (object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member SerializeToUtf8Bytes : obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> byte[]
Public Function SerializeToUtf8Bytes (value As Object, jsonTypeInfo As JsonTypeInfo) As Byte()

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

SerializeToUtf8Bytes(Object, Type, JsonSerializerContext)

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

Converts the provided value into a Byte array.

public:
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static byte[] SerializeToUtf8Bytes (object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member SerializeToUtf8Bytes : obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> byte[]
Public Function SerializeToUtf8Bytes (value As Object, inputType As Type, context As JsonSerializerContext) As Byte()

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

SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)

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.

public static byte[] SerializeToUtf8Bytes<TValue> (TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static byte[] SerializeToUtf8Bytes<TValue> (TValue value, System.Text.Json.JsonSerializerOptions options = default);
static member SerializeToUtf8Bytes : 'Value * System.Text.Json.JsonSerializerOptions -> byte[]
Public Shared Function SerializeToUtf8Bytes(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As Byte()
Public Function SerializeToUtf8Bytes(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As Byte()

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

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

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

Converts the provided value into a Byte array.

public:
generic <typename TValue>
 static cli::array <System::Byte> ^ SerializeToUtf8Bytes(TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static byte[] SerializeToUtf8Bytes<TValue> (TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member SerializeToUtf8Bytes : 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> byte[]
Public Function SerializeToUtf8Bytes(Of TValue) (value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue)) As Byte()

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