JsonBridgeCodec class final
The default codec — encodes via toJson() / decodes via TypeRegistry.
How Encoding Works
- If
valueisnull, a primitive, Map, or List, it is passed through. - If
valuehas atoJson()method (duck typing), it is called. - If a TypeAdapter is registered for
value.runtimeType, itstoMapfunction is called. - Otherwise, BridgeEncodeException is thrown.
How Decoding Works
- If
Tis a primitive type (String,int,double,bool,void),rawis cast directly. - If a TypeAdapter<T> is registered in TypeRegistry, its
fromMapfunction is called withrawas a Map<String, Object?>. - If
TisMapordynamic,rawis returned as-is. - 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
rawtransport data into an instance ofT.override -
encode(
Object? value, {Type? hint}) → Object? -
Encodes
valueinto 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