JsonMessageCodec<T> constructor

const JsonMessageCodec<T>({
  1. required Map<String, dynamic>? toJson(
    1. T
    ),
  2. required T? fromJson(
    1. Map<String, dynamic>
    ),
  3. Object? toEncodable(
    1. Object? nonEncodable
    )?,
  4. Object? reviver(
    1. Object? key,
    2. Object? value
    )?,
})

A message codec that uses JSON for serialization.

This codec allows for custom handling of non-standard JSON types by accepting optional toEncodable and reviver functions, which are passed directly to jsonEncode and jsonDecode respectively.

Creates a JsonMessageCodec.

toJson is a function that converts an object of type T to a Map<String, dynamic>. fromJson is a function that creates an object of type T from a Map<String, dynamic>. toEncodable is an optional function passed to jsonEncode to handle objects that are not directly encodable to JSON. reviver is an optional function passed to jsonDecode to transform decoded values.

Implementation

const JsonMessageCodec({
  required Map<String, dynamic>? Function(T) toJson,
  required T? Function(Map<String, dynamic>) fromJson,
  Object? Function(Object? nonEncodable)? toEncodable,
  Object? Function(Object? key, Object? value)? reviver,
})  : _toJson = toJson,
      _fromJson = fromJson,
      _toEncodable = toEncodable,
      _reviver = reviver;