Class NewtonsoftSerializer
- Namespace
- Akavache.NewtonsoftJson
- Assembly
- Akavache.NewtonsoftJson.dll
A unified serializer using Newtonsoft.Json with automatic format detection. Supports both JSON and BSON formats for maximum compatibility with Akavache.
public class NewtonsoftSerializer : ISerializer
- Inheritance
-
NewtonsoftSerializer
- Implements
- Derived
- Extension Methods
Constructors
NewtonsoftSerializer()
public NewtonsoftSerializer()
Properties
ForcedDateTimeKind
Gets or sets the DateTimeKind handling for BSON readers to be forced.
public DateTimeKind? ForcedDateTimeKind { get; set; }
Property Value
Remarks
By default, BsonReader uses a DateTimeKind of Local and see BsonWriter
uses Utc. Thus, DateTimes are serialized as UTC but deserialized as local time. To force BSON readers to
use some other DateTimeKind, you can set this value.
Options
Gets or sets the JSON serializer settings for customizing serialization behavior.
public JsonSerializerSettings? Options { get; set; }
Property Value
- JsonSerializerSettings
UseBsonFormat
Gets or sets a value indicating whether to use BSON format for serialization. When true, serializes to BSON for maximum Akavache compatibility. When false (default), serializes to JSON for better readability.
public bool UseBsonFormat { get; set; }
Property Value
Methods
Deserialize<T>(byte[])
Deserializes from bytes.
[RequiresUnreferencedCode("Using Newtonsoft.Json requires types to be preserved for deserialization.")]
[RequiresDynamicCode("Using Newtonsoft.Json requires types to be preserved for deserialization.")]
public T? Deserialize<T>(byte[] bytes)
Parameters
bytesbyte[]The bytes.
Returns
- T
The type.
Type Parameters
TThe type to deserialize to.
IsPotentialBsonData(byte[])
Checks if data might be BSON format.
public static bool IsPotentialBsonData(byte[] data)
Parameters
databyte[]The data to check.
Returns
- bool
True if data might be BSON.
Serialize<T>(T)
Serializes to an bytes.
[RequiresUnreferencedCode("Using Newtonsoft.Json requires types to be preserved for serialization.")]
[RequiresDynamicCode("Using Newtonsoft.Json requires types to be preserved for serialization.")]
public byte[] Serialize<T>(T item)
Parameters
itemTThe item to serialize.
Returns
- byte[]
The bytes.
Type Parameters
TThe type of serialize.