Quartz.Serialization.Json 3.10.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Quartz.Serialization.Json --version 3.10.0                
NuGet\Install-Package Quartz.Serialization.Json -Version 3.10.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Quartz.Serialization.Json" Version="3.10.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Quartz.Serialization.Json --version 3.10.0                
#r "nuget: Quartz.Serialization.Json, 3.10.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Quartz.Serialization.Json as a Cake Addin
#addin nuget:?package=Quartz.Serialization.Json&version=3.10.0

// Install Quartz.Serialization.Json as a Cake Tool
#tool nuget:?package=Quartz.Serialization.Json&version=3.10.0                

::: tip JSON is recommended persistent format to store data in database for greenfield projects. You should also strongly consider setting useProperties to true to restrict key-values to be strings. :::

Quartz.Serialization.Json provides JSON serialization support for job stores using Json.NET to handle the actual serialization process.

Installation

You need to add NuGet package reference to your project which uses Quartz.

Install-Package Quartz.Serialization.Json

Configuring

Classic property-based configuration

var properties = new NameValueCollection
{
	["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
	// "newtonsoft" and "json" are aliases for "Quartz.Simpl.JsonObjectSerializer, Quartz.Serialization.Json" 
	// you should prefer "newtonsoft" as it's more explicit from Quartz 3.10 onwards
	["quartz.serializer.type"] = "newtonsoft"
};
ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);

Configuring using scheduler builder

var config = SchedulerBuilder.Create();
config.UsePersistentStore(store =>
{
    // it's generally recommended to stick with
    // string property keys and values when serializing
    store.UseProperties = true;
    store.UseGenericDatabase(dbProvider, db =>
        db.ConnectionString = "my connection string"
    );

    store.UseNewtonsoftJsonSerializer();
});
ISchedulerFactory schedulerFactory = config.Build();

Migrating from binary serialization

There's now official solution for migration as there can be quirks in every setup, but there's a recipe that can work for you.

  • Configure custom serializer like MigratorSerializer below that can read binary serialization format and writes JSON format
  • Either let system gradually migrate as it's running or create a program which loads and writes back to DB all relevant serialized assets

Example hybrid serializer

public class MigratorSerializer : IObjectSerializer
{
    private BinaryObjectSerializer binarySerializer;
    private JsonObjectSerializer jsonSerializer;

    public MigratorSerializer()
    {
        this.binarySerializer = new BinaryObjectSerializer();
        // you might need custom configuration, see sections about customizing
        // in documentation
        this.jsonSerializer = new JsonObjectSerializer();
    }

    public T DeSerialize<T>(byte[] data) where T : class
    {
        try
        {
            // Attempt to deserialize data as JSON
            var result = this.jsonSerializer.DeSerialize<T>(data);
            return result;
        }
        catch (JsonReaderException)
        {
            // Presumably, the data was not JSON, we instead use the binary serializer
            return this.binarySerializer.DeSerialize<T>(data);
        }
    }

    public void Initialize()
    {
        this.binarySerializer.Initialize();
        this.jsonSerializer.Initialize();
    }

    public byte[] Serialize<T>(T obj) where T : class
    {
        return this.jsonSerializer.Serialize<T>(obj);
    }
}

Customizing JSON.NET

If you need to customize JSON.NET settings, you need to inherit custom implementation and override CreateSerializerSettings.

class CustomJsonSerializer : JsonObjectSerializer
{
   protected override JsonSerializerSettings CreateSerializerSettings()
   {
       var settings = base.CreateSerializerSettings();
       settings.Converters.Add(new MyCustomConverter());
       return settings;
   }
} 

And then configure it to use

store.UseSerializer<CustomJsonSerializer>();
// or 
"quartz.serializer.type" = "MyProject.CustomJsonSerializer, MyProject"

Customizing calendar serialization

If you have implemented a custom calendar, you need to implement a ICalendarSerializer for it. There's a convenience base class CalendarSerializer that you can use the get strongly-typed experience.

Custom calendar and serializer

[Serializable]
class CustomCalendar : BaseCalendar
{
    public CustomCalendar()
    {
    }

    // binary serialization support
    protected CustomCalendar(SerializationInfo info, StreamingContext context) : base(info, context)
    {
        SomeCustomProperty = info?.GetBoolean("SomeCustomProperty") ?? true;
    }

    public bool SomeCustomProperty { get; set; } = true;

    // binary serialization support
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        base.GetObjectData(info, context);
        info?.AddValue("SomeCustomProperty", SomeCustomProperty);
    }
}

// JSON serialization support
class CustomCalendarSerializer : CalendarSerializer<CustomCalendar>
{
    protected override CustomCalendar Create(JObject source)
    {
        return new CustomCalendar();
    }

    protected override void SerializeFields(JsonWriter writer, CustomCalendar calendar)
    {
        writer.WritePropertyName("SomeCustomProperty");
        writer.WriteValue(calendar.SomeCustomProperty);
    }

    protected override void DeserializeFields(CustomCalendar calendar, JObject source)
    {
        calendar.SomeCustomProperty = source["SomeCustomProperty"]!.Value<bool>();
    }
}

Configuring custom calendar serializer

var config = SchedulerBuilder.Create();
config.UsePersistentStore(store =>
{
    store.UseJsonSerializer(json =>
    {
        json.AddCalendarSerializer<CustomCalendar>(new CustomCalendarSerializer());
    });
});

// or just globally which is what above code calls
JsonObjectSerializer.AddCalendarSerializer<CustomCalendar>(new CustomCalendarSerializer());
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (73)

Showing the top 5 NuGet packages that depend on Quartz.Serialization.Json:

Package Downloads
SyncSoft.ECP.Quartz

An ecommerce framework for SyncSoft Inc.

RapidFire.Core

Rapid Fire For WEB with .NET 6!

Zq.Utils.Core

.NET Standard2.0、.NET Standard2.1、.NET5、.NET6版本工具类

SyncSoft.ECP.Hosting

An app framework for SyncSoft Inc.

NetModular.Lib.Quartz.Abstractions

NetModular quartz abstractions

GitHub repositories (16)

Showing the top 5 popular GitHub repositories that depend on Quartz.Serialization.Json:

Repository Stars
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
elsa-workflows/elsa-core
A .NET workflows library
oskardudycz/EventSourcing.NetCore
Examples and Tutorials of Event Sourcing in .NET
zhaopeiym/quartzui
基于Quartz.NET3.0的定时任务Web可视化管理。docker打包开箱即用、内置SQLite持久化、语言无关、业务代码零污染、支持 RESTful风格接口、傻瓜式配置
iamoldli/NetModular
NetModular 是基于.Net Core 和 Vue.js 的业务模块化以及前后端分离的快速开发框架
Version Downloads Last updated
3.13.1 109,489 11/2/2024
3.13.0 532,935 8/10/2024
3.12.0 43,389 8/3/2024
3.11.0 572,890 7/7/2024
3.10.0 112,387 6/26/2024
3.9.0 569,385 5/9/2024
3.8.1 880,517 2/17/2024
3.8.0 879,185 11/18/2023
3.7.0 1,081,535 8/4/2023
3.6.3 352,156 6/25/2023
3.6.2 1,488,651 2/25/2023
3.6.1 381 2/25/2023
3.6.0 273,422 1/29/2023
3.5.0 954,755 9/18/2022
3.4.0 1,886,786 3/27/2022
3.3.3 1,614,541 8/1/2021
3.3.2 651,977 4/9/2021
3.3.1 4,951 4/8/2021
3.3.0 10,471 4/7/2021
3.2.4 370,077 1/19/2021
3.2.3 507,307 10/31/2020
3.2.2 226,060 10/19/2020
3.2.1 4,815 10/18/2020
3.2.0 69,655 10/2/2020
3.1.0 293,505 7/24/2020
3.0.7 1,570,271 10/7/2018
3.0.6 154,017 7/6/2018
3.0.5 166,659 5/27/2018
3.0.4 105,314 3/4/2018
3.0.3 3,021 2/24/2018
3.0.2 16,964 1/25/2018
3.0.1 3,272 1/21/2018
3.0.0 47,312 12/30/2017
3.0.0-beta1 15,348 10/8/2017
3.0.0-alpha3 8,674 7/30/2017
3.0.0-alpha2 54,999 8/24/2016
3.0.0-alpha1 1,331 8/16/2016