Class NewtonsoftJsonSerializer

public class NewtonsoftJsonSerializer : object, 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
TypeNameDescription
JsonSerializerSettingssettings

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
TypeDescription
String

Instance

public static NewtonsoftJsonSerializer Instance { get; }

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

Property Value
TypeDescription
NewtonsoftJsonSerializer

Methods

CreateDefaultSettings()

public static JsonSerializerSettings CreateDefaultSettings()

Creates a new instance of 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
TypeDescription
JsonSerializerSettings

A new set of default settings.

Deserialize(String, Type)

public object Deserialize(string input, Type type)

Deserializes the string into an object.

Parameters
TypeNameDescription
Stringinput
Typetype
Returns
TypeDescription
Object

Deserialize<T>(Stream)

public T Deserialize<T>(Stream input)

Deserializes the stream into an object.

Parameter
TypeNameDescription
Streaminput
Returns
TypeDescription
T
Type Parameter
NameDescription
T

Deserialize<T>(String)

public T Deserialize<T>(string input)

Deserializes the string into an object.

Parameter
TypeNameDescription
Stringinput
Returns
TypeDescription
T
Type Parameter
NameDescription
T

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
TypeNameDescription
Streaminput

The stream to read from.

CancellationTokencancellationToken

Cancellation token for the operation.

Returns
TypeDescription
Task<T>

The deserialized object.

Type Parameter
NameDescription
T

The type to convert to.

Serialize(Object)

public string Serialize(object obj)

Serializes the specified object into a string.

Parameter
TypeNameDescription
Objectobj
Returns
TypeDescription
String

Serialize(Object, Stream)

public void Serialize(object obj, Stream target)

Serializes the specified object into a Stream.

Parameters
TypeNameDescription
Objectobj
Streamtarget

Implements

Extension Method