Class NewtonsoftJsonSerializer (1.68.0)

public class NewtonsoftJsonSerializer : IJsonSerializer, ISerializer

Class for serialization and deserialization of JSON documents using the Newtonsoft Library.

Inheritance

object > NewtonsoftJsonSerializer

Namespace

Google.Apis.Json

Assembly

Google.Apis.Core.dll

Constructors

NewtonsoftJsonSerializer()

public NewtonsoftJsonSerializer()

Constructs a new instance with the default serialization settings, equivalent to Instance.

NewtonsoftJsonSerializer(JsonSerializerSettings)

public NewtonsoftJsonSerializer(JsonSerializerSettings settings)

Constructs a new instance with the given settings.

Parameter
Name Description
settings Newtonsoft.Json.JsonSerializerSettings

The settings to apply when serializing and deserializing. Must not be null.

Properties

Format

public string Format { get; }

Gets the application format this serializer supports (e.g. "json", "xml", etc.).

Property Value
Type Description
string

Instance

public static NewtonsoftJsonSerializer Instance { get; }

The default instance of the Newtonsoft JSON Serializer, with default settings.

Property Value
Type Description
NewtonsoftJsonSerializer

Methods

CreateDefaultSettings()

public static JsonSerializerSettings CreateDefaultSettings()

Creates a new instance of Newtonsoft.Json.JsonSerializerSettings with the same behavior as the ones used in Instance. This method is expected to be used to construct settings which are then passed to NewtonsoftJsonSerializer(JsonSerializerSettings).

Returns
Type Description
Newtonsoft.Json.JsonSerializerSettings

A new set of default settings.

Deserialize(string, Type)

public object Deserialize(string input, Type type)

Deserializes the string into an object.

Parameters
Name Description
input string
type Type
Returns
Type Description
object

DeserializeAsync<T>(Stream, CancellationToken)

public Task<T> DeserializeAsync<T>(Stream input, CancellationToken cancellationToken)

Deserializes the given stream but reads from it asynchronously, observing the given cancellation token. Note that this means the complete JSON is read before it is deserialized into objects.

Parameters
Name Description
input Stream

The stream to read from.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns
Type Description
Task

The deserialized object.

Type Parameter
Name Description
T

The type to convert to.

Deserialize<T>(Stream)

public T Deserialize<T>(Stream input)

Deserializes the stream into an object.

Parameter
Name Description
input Stream
Returns
Type Description
T
Type Parameter
Name Description
T

Deserialize<T>(string)

public T Deserialize<T>(string input)

Deserializes the string into an object.

Parameter
Name Description
input string
Returns
Type Description
T
Type Parameter
Name Description
T

Serialize(object)

public string Serialize(object obj)

Serializes the specified object into a string.

Parameter
Name Description
obj object
Returns
Type Description
string

Serialize(object, Stream)

public void Serialize(object obj, Stream target)

Serializes the specified object into a Stream.

Parameters
Name Description
obj object
target Stream

Extension Method