Table of Contents

Class JsonSerializer

Namespace
Newtonsoft.Json
Assembly
Newtonsoft.Json.dll

Serializes and deserializes objects into and from the JSON format. The JsonSerializer enables you to control how objects are encoded into JSON.

public class JsonSerializer
Inheritance
JsonSerializer
Inherited Members

Constructors

JsonSerializer()

Initializes a new instance of the JsonSerializer class.

public JsonSerializer()

Properties

Binder

Gets or sets the SerializationBinder used by the serializer when resolving type names.

public virtual SerializationBinder Binder { get; set; }

Property Value

SerializationBinder

ConstructorHandling

Gets or sets how constructors are used during deserialization.

public virtual ConstructorHandling ConstructorHandling { get; set; }

Property Value

ConstructorHandling

The constructor handling.

Context

Gets or sets the StreamingContext used by the serializer when invoking serialization callback methods.

public virtual StreamingContext Context { get; set; }

Property Value

StreamingContext

The context.

ContractResolver

Gets or sets the contract resolver used by the serializer when serializing .NET objects to JSON and vice versa.

public virtual IContractResolver ContractResolver { get; set; }

Property Value

IContractResolver

Converters

Gets a collection JsonConverter that will be used during serialization.

public virtual JsonConverterCollection Converters { get; }

Property Value

JsonConverterCollection

Collection JsonConverter that will be used during serialization.

DefaultValueHandling

Get or set how null default are handled during serialization and deserialization.

public virtual DefaultValueHandling DefaultValueHandling { get; set; }

Property Value

DefaultValueHandling

MissingMemberHandling

Get or set how missing members (e.g. JSON contains a property that isn't a member on the object) are handled during deserialization.

public virtual MissingMemberHandling MissingMemberHandling { get; set; }

Property Value

MissingMemberHandling

NullValueHandling

Get or set how null values are handled during serialization and deserialization.

public virtual NullValueHandling NullValueHandling { get; set; }

Property Value

NullValueHandling

ObjectCreationHandling

Gets or sets how objects are created during deserialization.

public virtual ObjectCreationHandling ObjectCreationHandling { get; set; }

Property Value

ObjectCreationHandling

The object creation handling.

PreserveReferencesHandling

Gets or sets how object references are preserved by the serializer.

public virtual PreserveReferencesHandling PreserveReferencesHandling { get; set; }

Property Value

PreserveReferencesHandling

ReferenceLoopHandling

Get or set how reference loops (e.g. a class referencing itself) is handled.

public virtual ReferenceLoopHandling ReferenceLoopHandling { get; set; }

Property Value

ReferenceLoopHandling

ReferenceResolver

Gets or sets the IReferenceResolver used by the serializer when resolving references.

public virtual IReferenceResolver ReferenceResolver { get; set; }

Property Value

IReferenceResolver

TypeNameAssemblyFormat

Gets or sets how a type name assembly is written and resolved by the serializer.

public virtual FormatterAssemblyStyle TypeNameAssemblyFormat { get; set; }

Property Value

FormatterAssemblyStyle

The type name assembly format.

TypeNameHandling

Gets or sets how type name writing and reading is handled by the serializer.

public virtual TypeNameHandling TypeNameHandling { get; set; }

Property Value

TypeNameHandling

Methods

Create(JsonSerializerSettings)

Creates a new JsonSerializer instance using the specified JsonSerializerSettings.

public static JsonSerializer Create(JsonSerializerSettings settings)

Parameters

settings JsonSerializerSettings

The settings to be applied to the JsonSerializer.

Returns

JsonSerializer

A new JsonSerializer instance using the specified JsonSerializerSettings.

Deserialize(JsonReader)

Deserializes the Json structure contained by the specified JsonReader.

public object Deserialize(JsonReader reader)

Parameters

reader JsonReader

The JsonReader that contains the JSON structure to deserialize.

Returns

object

The object being deserialized.

Deserialize(JsonReader, Type)

Deserializes the Json structure contained by the specified JsonReader into an instance of the specified type.

public object Deserialize(JsonReader reader, Type objectType)

Parameters

reader JsonReader

The JsonReader containing the object.

objectType Type

The Type of object being deserialized.

Returns

object

The instance of objectType being deserialized.

Deserialize(TextReader, Type)

Deserializes the Json structure contained by the specified StringReader into an instance of the specified type.

public object Deserialize(TextReader reader, Type objectType)

Parameters

reader TextReader

The TextReader containing the object.

objectType Type

The Type of object being deserialized.

Returns

object

The instance of objectType being deserialized.

Deserialize<T>(JsonReader)

Deserializes the Json structure contained by the specified JsonReader into an instance of the specified type.

public T Deserialize<T>(JsonReader reader)

Parameters

reader JsonReader

The JsonReader containing the object.

Returns

T

The instance of T being deserialized.

Type Parameters

T

The type of the object to deserialize.

Populate(JsonReader, object)

Populates the JSON values onto the target object.

public void Populate(JsonReader reader, object target)

Parameters

reader JsonReader

The JsonReader that contains the JSON structure to reader values from.

target object

The target object to populate values onto.

Populate(TextReader, object)

Populates the JSON values onto the target object.

public void Populate(TextReader reader, object target)

Parameters

reader TextReader

The TextReader that contains the JSON structure to reader values from.

target object

The target object to populate values onto.

Serialize(JsonWriter, object)

Serializes the specified object and writes the Json structure to a Stream using the specified JsonWriter.

public void Serialize(JsonWriter jsonWriter, object value)

Parameters

jsonWriter JsonWriter

The JsonWriter used to write the Json structure.

value object

The object to serialize.

Serialize(TextWriter, object)

Serializes the specified object and writes the Json structure to a Stream using the specified TextWriter.

public void Serialize(TextWriter textWriter, object value)

Parameters

textWriter TextWriter

The TextWriter used to write the Json structure.

value object

The object to serialize.

Events

Error

Occurs when the JsonSerializer errors during serialization and deserialization.

public virtual event EventHandler<ErrorEventArgs> Error

Event Type

EventHandler<ErrorEventArgs>