Class NewtonsoftJsonSerializer (1.55.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
NameDescription
settingsJsonSerializerSettings

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
NameDescription
inputString
typeType
Returns
TypeDescription
Object

Deserialize<T>(Stream)

public T Deserialize<T>(Stream input)

Deserializes the stream into an object.

Parameter
NameDescription
inputStream
Returns
TypeDescription
T
Type Parameter
NameDescription
T

Deserialize<T>(String)

public T Deserialize<T>(string input)

Deserializes the string into an object.

Parameter
NameDescription
inputString
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
NameDescription
inputStream

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
NameDescription
objObject
Returns
TypeDescription
String

Serialize(Object, Stream)

public void Serialize(object obj, Stream target)

Serializes the specified object into a Stream.

Parameters
NameDescription
objObject
targetStream

Extension Method