Custom classes

Any classes that are not pass-through classes must be handled by registering hooks for them. DeterministicJsonSerializer has some predefined hooks registered and thus supports (de)serialization of the following built-in types out of the box:

class

output

tuple

list

set

sorted list

frozenset

sorted list

dict

sorted list of (key, value) pair lists

MappingProxyType

sorted list of (key, value) pair lists

Enum

element name as str

type

class name as str

GenericAlias

dict with fields “origin” and “args” containing the class names of origin and args classes

dataclass

dict with serialized fields from dataclasses.fields

attrs classes

dict with serialized fields from attrs.fields

For any custom classes not belonging to the built-in supported classes, class hooks or predicate hooks facilitating their (de)serialization can be registered with the serializer.