JsonBridgeCodec class final

The default codec — encodes via toJson() / decodes via TypeRegistry.

How Encoding Works

  1. If value is null, a primitive, Map, or List, it is passed through.
  2. If value has a toJson() method (duck typing), it is called.
  3. If a TypeAdapter is registered for value.runtimeType, its toMap function is called.
  4. Otherwise, BridgeEncodeException is thrown.

How Decoding Works

  1. If T is a primitive type (String, int, double, bool, void), raw is cast directly.
  2. If a TypeAdapter<T> is registered in TypeRegistry, its fromMap function is called with raw as a Map<String, Object?>.
  3. If T is Map or dynamic, raw is returned as-is.
  4. Otherwise, BridgeDecodeException is thrown.

Uint8List Handling

When a Uint8List field is encountered inside a JSON-encoded map, it is encoded as a Base64 string (prefix: "b64:"). The decoder recognizes this prefix and reverses the encoding. This is documented clearly as the expected fallback behaviour for JSON transport.

Implemented types

Constructors

JsonBridgeCodec({TypeRegistry? registry})
Creates a JsonBridgeCodec.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
id String
A unique identifier for this codec.
no setteroverride
registry TypeRegistry?
The type registry for resolving TypeAdapters during decode.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decode<T>(Object? raw, {Type? hint}) → T
Decodes raw transport data into an instance of T.
override
encode(Object? value, {Type? hint}) Object?
Encodes value into a transport-safe representation.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited