Class NewtonsoftJsonSerializer
Class for serialization and deserialization of JSON documents using the Newtonsoft Library.
Inherited Members
Namespace: Google.Apis.Json
Assembly: Google.Apis.Core.dll
Syntax
public class NewtonsoftJsonSerializer : IJsonSerializer, ISerializer
Constructors
NewtonsoftJsonSerializer()
Constructs a new instance with the default serialization settings, equivalent to Instance.
Declaration
public NewtonsoftJsonSerializer()
NewtonsoftJsonSerializer(JsonSerializerSettings)
Constructs a new instance with the given settings.
Declaration
public NewtonsoftJsonSerializer(JsonSerializerSettings settings)
Parameters
Type | Name | Description |
---|---|---|
JsonSerializerSettings | settings | The settings to apply when serializing and deserializing. Must not be null. |
Properties
Format
Gets the application format this serializer supports (e.g. "json", "xml", etc.).
Declaration
public string Format { get; }
Property Value
Type | Description |
---|---|
string |
Instance
The default instance of the Newtonsoft JSON Serializer, with default settings.
Declaration
public static NewtonsoftJsonSerializer Instance { get; }
Property Value
Type | Description |
---|---|
NewtonsoftJsonSerializer |
Methods
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).
Declaration
public static JsonSerializerSettings CreateDefaultSettings()
Returns
Type | Description |
---|---|
JsonSerializerSettings | A new set of default settings. |
Deserialize(string, Type)
Deserializes the string into an object.
Declaration
public object Deserialize(string input, Type type)
Parameters
Type | Name | Description |
---|---|---|
string | input | |
Type | type |
Returns
Type | Description |
---|---|
object |
DeserializeAsync<T>(Stream, 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.
Declaration
public Task<T> DeserializeAsync<T>(Stream input, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream to read from. |
CancellationToken | cancellationToken | Cancellation token for the operation. |
Returns
Type | Description |
---|---|
Task<T> | The deserialized object. |
Type Parameters
Name | Description |
---|---|
T | The type to convert to. |
Deserialize<T>(Stream)
Deserializes the stream into an object.
Declaration
public T Deserialize<T>(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Deserialize<T>(string)
Deserializes the string into an object.
Declaration
public T Deserialize<T>(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Serialize(object)
Serializes the specified object into a string.
Declaration
public string Serialize(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
string |
Serialize(object, Stream)
Serializes the specified object into a Stream.
Declaration
public void Serialize(object obj, Stream target)
Parameters
Type | Name | Description |
---|---|---|
object | obj | |
Stream | target |