# Class NewtonsoftJsonSerializer (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Json.NewtonsoftJsonSerializer)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Json.NewtonsoftJsonSerializer)

    public class NewtonsoftJsonSerializer : IJsonSerializer, ISerializer

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

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> NewtonsoftJsonSerializer

## Implements

[IJsonSerializer](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.IJsonSerializer), [ISerializer](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.ISerializer)

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Json](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json)

## Assembly

Google.Apis.Core.dll

## Constructors

### NewtonsoftJsonSerializer()

    public NewtonsoftJsonSerializer()

Constructs a new instance with the default serialization settings, equivalent to [Instance](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.NewtonsoftJsonSerializer#Google_Apis_Json_NewtonsoftJsonSerializer_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** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Instance

    public static NewtonsoftJsonSerializer Instance { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.NewtonsoftJsonSerializer#Google_Apis_Json_NewtonsoftJsonSerializer_Instance). This method is expected to be used to construct
settings which are then passed to [NewtonsoftJsonSerializer(JsonSerializerSettings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Json.NewtonsoftJsonSerializer#Google_Apis_Json_NewtonsoftJsonSerializer__ctor_Newtonsoft_Json_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` | `https://learn.microsoft.com/dotnet/api/system.string` |
| `type` | `https://learn.microsoft.com/dotnet/api/system.type` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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` | `https://learn.microsoft.com/dotnet/api/system.io.stream` The stream to read from. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancellation token for the operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1` | 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` | `https://learn.microsoft.com/dotnet/api/system.io.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` | `https://learn.microsoft.com/dotnet/api/system.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` | `https://learn.microsoft.com/dotnet/api/system.object` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Serialize(object, Stream)

    public void Serialize(object obj, Stream target)

Serializes the specified object into a Stream.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://learn.microsoft.com/dotnet/api/system.object` |
| `target` | `https://learn.microsoft.com/dotnet/api/system.io.stream` |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)