DataContractJsonSerializer Class

Namespace: System.Runtime.Serialization

Assembly: System.Runtime.Serialization.dll

Summary

Represents a serializer that uses data contracts to serialize and deserialize objects to and from JavaScript Object Notation (JSON) format.

Remarks

The DataContractJsonSerializer class enables you to serialize objects into JSON format. This serializer is part of the Windows Communication Foundation (WCF) infrastructure but can be used independently to serialize and deserialize objects to and from JSON. It leverages the data contract model, which allows for fine-grained control over serialization.

Key features include:

  • Support for data contracts defined with the [DataContract] attribute.
  • Ability to serialize and deserialize common .NET types.
  • Configuration options for handling cyclic references, preserving object references, and specifying JSON formatting.

For more information on using DataContractJsonSerializer, refer to the official WCF documentation.

Members

Constructors

  • DataContractJsonSerializer()

    Initializes a new instance of the DataContractJsonSerializer class.

  • DataContractJsonSerializer(Type type)

    Initializes a new instance of the DataContractJsonSerializer class with the specified root type.

  • DataContractJsonSerializer(Type type, IEnumerable knownTypes)

    Initializes a new instance of the DataContractJsonSerializer class with the specified root type and a collection of known types.

  • DataContractJsonSerializer(Type type, DataContractJsonSerializerSettings settings)

    Initializes a new instance of the DataContractJsonSerializer class with the specified root type and serialization settings.

Methods

  • ReadObject(Stream stream)

    Deserializes a JSON-formatted object from a stream.

    Parameters

    stream The stream that contains the JSON-formatted object.

    Returns

    The deserialized object.

  • WriteObject(Stream stream, object o)

    Serializes an object to a stream in JSON format.

    Parameters

    stream The stream that will receive the JSON-formatted object.
    o The object to serialize.

Properties

  • IgnoreExtensionDataObject

    Gets or sets a value that indicates whether to ignore the ExtensionData property of the IExtensibleDataObject interface.

  • MaxItemsInObjectGraph

    Gets or sets the maximum number of items to serialize or deserialize in object graphs.

  • MaxDepth

    Gets or sets the maximum depth of the object graph.

See Also