description

# JsonCodec constructor Null safety

const JsonCodec(

1. {Object? reviver(
   1. Object? key,
   2. Object? value
   ),
2. Object? toEncodable(
   1. dynamic object
   )}

)

Creates a `JsonCodec` with the given reviver and encoding function.

The `reviver` function is called during decoding. It is invoked once for each object or list property that has been parsed. The `key` argument is either the integer list index for a list property, the string map key for object properties, or `null` for the final result.

If `reviver` is omitted, it defaults to returning the value argument.

The `toEncodable` function is used during encoding. It is invoked for values that are not directly encodable to a string (a value that is not a number, boolean, string, null, list or a map with string keys). The function must return an object that is directly encodable. The elements of a returned list and values of a returned map do not need to be directly encodable, and if they aren't, `toEncodable` will be used on them as well. Please notice that it is possible to cause an infinite recursive regress in this way, by effectively creating an infinite data structure through repeated call to `toEncodable`.

If `toEncodable` is omitted, it defaults to a function that returns the result of calling `.toJson()` on the unencodable object.

## Implementation

    const JsonCodec(
        {Object? reviver(Object? key, Object? value)?,
        Object? toEncodable(dynamic object)?})
        : _reviver = reviver,
          _toEncodable = toEncodable;