Table of Contents

Class NewtonsoftJsonSerializerRegistry

Namespace
Quartz.Serialization.Newtonsoft
Assembly
Quartz.Serialization.Newtonsoft.dll

The trigger and calendar serializers a NewtonsoftJsonObjectSerializer knows about.

public sealed class NewtonsoftJsonSerializerRegistry
Inheritance
NewtonsoftJsonSerializerRegistry
Inherited Members

Remarks

A new instance already knows every trigger and calendar type Quartz ships with, so registering a custom one adds to that set rather than replacing it.

These registrations used to live in process-global dictionaries inside the converters, which meant two schedulers in one process could not serialize different custom types — whichever registered last won, silently. Owning them per instance is what makes the choice belong to the scheduler that made it. Registrations are expected to be complete before the owning serializer is initialized; the maps are not synchronized for concurrent writes, exactly as the statics they replace were not.

Lookups mirror the System.Text.Json registry: case-insensitive, with a calendar indexed both under its assembly-qualified type name — which is what payloads written by 3.x carry, so that key always stays registered — and, when the serializer provides one, under its CalendarTypeName discriminator.

A registry is also where an application declares a job data value type of its own, through AddJobDataValueType<T>(). The serializer writes the value types a JobDataMap has an accessor for and refuses the rest, so that a value nothing can read back is refused while there is still someone to tell rather than stored and failed on later.

Constructors

NewtonsoftJsonSerializerRegistry()

Creates a registry holding the serializers for the built-in trigger and calendar types.

public NewtonsoftJsonSerializerRegistry()

Methods

AddCalendarSerializer<TCalendar>(CalendarSerializer<TCalendar>)

Adds a serializer for a custom calendar type.

public NewtonsoftJsonSerializerRegistry AddCalendarSerializer<TCalendar>(CalendarSerializer<TCalendar> serializer) where TCalendar : ICalendar

Parameters

serializer CalendarSerializer<TCalendar>

Returns

NewtonsoftJsonSerializerRegistry

Type Parameters

TCalendar

Remarks

The serializer is the typed CalendarSerializer<TCalendar> for this very calendar, so a mismatched pairing is a compile error rather than an InvalidCastException on the first calendar that round-trips. TCalendar is inferred from the argument, so the type argument can be left off.

AddJobDataValueType<T>()

Declares a job data value type of the application's own, which this serializer otherwise refuses to write.

public NewtonsoftJsonSerializerRegistry AddJobDataValueType<T>()

Returns

NewtonsoftJsonSerializerRegistry

Type Parameters

T

The exact runtime type of the values to accept. A declaration does not extend to a derived type, because it is the runtime type of the stored value that is looked up — declare each type you actually put in a map.

Remarks

A JobDataMap accepts the types DataMapExtensions declares an accessor for, plus a Dictionary<string, string>; anything else is refused when the job or trigger is stored, rather than written as a blob that fails to load later. This is how an application says a type of its own is one Json.NET can read back — a class with a constructor Json.NET can call, and a versioning commitment for as long as the value sits in the database.

It is this package's counterpart to SystemTextJsonSerializerRegistry.AddTypeInfoResolver, and the narrower of the two: Json.NET needs no metadata handed to it, so nothing is registered here but the permission. A blob holding a declared type is readable by this serializer only — the System.Text.Json reader hands any object back as a Dictionary<string, string> — so a value that has to survive a change of serializer belongs in a string the job writes itself.

AddTriggerSerializer<TTrigger>(ITriggerSerializer)

Adds a serializer for a custom trigger type.

public NewtonsoftJsonSerializerRegistry AddTriggerSerializer<TTrigger>(ITriggerSerializer serializer) where TTrigger : ITrigger

Parameters

serializer ITriggerSerializer

Returns

NewtonsoftJsonSerializerRegistry

Type Parameters

TTrigger