Table of Contents

Class JsonValueReaderWriter

Namespace
Microsoft.EntityFrameworkCore.Storage.Json
Assembly
Microsoft.EntityFrameworkCore.dll

Reads and writes the JSON value for a given model or provider value.

public abstract class JsonValueReaderWriter
Inheritance
JsonValueReaderWriter
Derived
Inherited Members

Remarks

Implementations of this type must inherit from the generic JsonValueReaderWriter<TValue>

Properties

ValueType

The type of the value being read/written.

public abstract Type ValueType { get; }

Property Value

Type

Methods

CreateFromType(Type?)

Creates a JsonValueReaderWriter<TValue> instance of the given type, using the Instance property to get th singleton instance if possible.

public static JsonValueReaderWriter? CreateFromType(Type? readerWriterType)

Parameters

readerWriterType Type

The type, which must inherit from JsonValueReaderWriter<TValue>.

Returns

JsonValueReaderWriter

The reader/writer instance./

Exceptions

InvalidOperationException

if the type does not represent a JsonValueReaderWriter<TValue> that can be instantiated.

FromJson(ref Utf8JsonReaderManager, object?)

Reads the value from a UTF8 JSON stream or buffer.

public abstract object FromJson(ref Utf8JsonReaderManager manager, object? existingObject = null)

Parameters

manager Utf8JsonReaderManager

The Utf8JsonReaderManager for the JSON being read.

existingObject object

Can be used to update an existing object, rather than create a new one.

Returns

object

The read value.

Remarks

The CurrentReader is at the node that contains the value to be read. The value should be read as appropriate from the JSON, and then further converted as necessary.

Nulls are handled externally to this reader. That is, this method will never be called if the JSON value is "null".

In most cases, the value is represented in the JSON document as a simple property value--e.g. a number, boolean, or string. However, it could be an array or sub-document. In this case, the Utf8JsonReaderManager should be used to parse the JSON as appropriate.

FromJsonString(string, object?)

Reads the value from JSON in a string.

public object FromJsonString(string json, object? existingObject = null)

Parameters

json string

The JSON to parse.

existingObject object

Can be used to update an existing object, rather than create a new one.

Returns

object

The read value.

ToJson(Utf8JsonWriter, object)

Writes the value to JSON.

public abstract void ToJson(Utf8JsonWriter writer, object value)

Parameters

writer Utf8JsonWriter

The Utf8JsonWriter into which the value should be written.

value object

The value to write.

ToJsonString(object)

Writes the value to a JSON string.

public string ToJsonString(object value)

Parameters

value object

The value to write.

Returns

string

The JSON representation of the given value.