Class Tagging Strategies¶

The class_tagger in a Serializer is responsible for

  • generating class tags from objects for serialization

  • determining the target class from a class tag in the serialized data for deserialization.

The DeterministicJsonSerializer uses a NameClassTagger as default, which generates tags based on class names and keeps an internal mapping between tags and imported classes. Other strategies can be used by passing other class objects that implement the ClassTagger interface for the class_tagger parameter.

This library supplies two built-in class taggers

In the Example 2 we needed to register custom classes AFoo, DFoo, Bar, Parity with the serializer’s NameClassTagger. See NameClassTagger for details and ImportPathClassTagger for a strategy where this step is not necessary. DeterministicJsonSerializer however uses NameClassTagger as default as it is more robust against moving classes during refactoring.