EnumAwareJson

internal class EnumAwareJson(base: Json)

The registered enums' serializers, as a module and as a Json with that module folded in, both rebuilt only when the set of registrations changes.

They cannot be composed once and kept: a client is built before anything is registered on it, and the enums arrive afterwards - named one by one, or all at once by a classpath scan. So the base is kept as it was given and the derived pair is resolved per conversion. That costs a volatile read and a reference comparison, because the driver replaces ConverterRegistry.registeredEnums wholesale on each registration: the map's identity is the version, and a reader that sees the map it saw last time gets back what it built last time.

The base's own registrations win over the generated ones, so an application that wrote a serializer for one of its enums keeps it and the rest are filled in.

Constructors

Link copied to clipboard
constructor(base: Json)

Functions

Link copied to clipboard
fun module(registry: ConverterRegistry): SerializersModule

The module on its own, for a Json the caller is building rather than one being converted with.

Link copied to clipboard
fun resolve(registry: ConverterRegistry): Json

base with the module folded in, or base itself where there is nothing to fold.