MosaicSerializer
The polymorphic JSON serializer shared by mosaic-server and mosaic-client — the single source of truth for how a TileSchema/EventSchema/EventTrigger subtype resolves to and from JSON, and the mechanism that lets a wire payload carry a mix of built-in and third-party-registered types indistinguishably.
Every polymorphic hierarchy is registered by @SerialName (each schema's own class carries one), not by any custom discriminator logic — this class only decides which classes participate. The built-in catalog is always registered (via the private defaultTileSerializers/ defaultEventSerializers/defaultEventTriggerSerializers maps at the bottom of this file, one entry per shipped TileSchema/EventSchema/EventTrigger); the tileSerializers/ eventSerializers/eventTriggerSerializers constructor parameters add third-party ones on top — this is exactly what mosaic-client's MosaicModules builds from a consuming app's MosaicDependencyInjectionConfig.tileDefinitions/eventDefinitions/eventTriggerDefinition. A class present in both a default map and one of these parameters would collide; the framework never does this itself, since the built-in classes and any third-party ones are necessarily distinct types.
Beyond the top-level TileSchema/EventSchema/EventTrigger hierarchies, the json builder also registers every nested sealed polymorphic type a schema declares internally (e.g. TextFieldTileSchema.VisualTransformation, EvaluateDataEventSchema.Expression and its whole operation tree, AddTilesEventSchema.InsertionPosition, the various Where/Direction/FileType sealed types) — those aren't extensible by third parties the way the 3 top-level hierarchies are, since they're closed sealed types owned entirely by their enclosing built-in schema.
Json is configured with explicitNulls = false (an omitted field decodes as null rather than failing), encodeDefaults = true (default-valued fields are still written to the wire, so a client decoding an older/newer schema version still sees every field explicitly), and ignoreUnknownKeys = true (an unrecognized field is silently dropped rather than failing decode — the mechanism that keeps server and client tolerant of small version skew).
Parameters
third-party TileSchema registrations, merged with the built-in catalog.
third-party EventSchema registrations, merged with the built-in catalog.
third-party EventTrigger registrations, merged with the built-in catalog.
extra polymorphic serializers unrelated to the 3 hierarchies above — for a field type that itself needs its own serializer registration, independent of tile/event/trigger registration.
Constructors
Properties
The configured Json instance every method on this class delegates to. Exposed directly (rather than kept private) for callers that need to hand it to a lower-level API expecting a plain kotlinx.serialization Json — e.g. Ktor's ContentNegotiation plugin (json(get<MosaicSerializer>().json)).
Functions
Same as decodeTileFromJsonElement, for an EventSchema — the mechanism behind EventRunnerDataProcessor decoding a broadcast/pushed payload as an event to run inline, and MosaicRepository's own screen-payload decoding.
Decodes element as T using the given deserializer explicitly — the general escape hatch for a caller that already has its own DeserializationStrategy and a JsonElement rather than a raw string.
Decodes jsonElement as a TileSchema, resolving the concrete subtype polymorphically by its own @SerialName — the general entry point for decoding one tile out of a JSON tree whose concrete type isn't known ahead of time (e.g. one entry of a tiles array).
Same as encodeTileToJsonElement, for an EventSchema — used by EventHolder.update.
Encodes tile to a JsonElement, resolving its serializer from its own runtime class — the mechanism TileHolder.update uses to encode a tile's current state before merging a JSON patch onto it, without the generic TileHolder<T> needing to know T's concrete serializer ahead of time.
Encodes value to a JsonElement tree (not a string) using the given serializer.
Encodes value to a JSON string, resolving T's serializer from this serializer's own serializersModule via reification — the convenient overload for a caller that has a compile-time type to encode, rather than an explicit SerializationStrategy.
Encodes value to a JSON string using the given serializer explicitly (rather than one resolved from T's reified type) — the general escape hatch for a caller that already has its own SerializationStrategy.
Parses string into a raw JsonElement tree, without decoding it into any typed model — the first step before a polymorphic decode call that needs the tree to inspect/merge before committing to a concrete type.