Provide Encoding/DecodingContext to MappingHook methods
I want to use dart_mappable's container and its mappers and for most properties its default mapping. However I have my own model metadata and want to filter all keys and values output for each model. So you might say to use afterEncode on a MappingHook, which I am trying to do. But in that method there is no context at all. All I have is the prospective output Map, not even the original model (for which I can access my metadata) or the container with its mappers for each property.
If I use beforeEncode I get the original model, but I lose the default encoding of the properties, and still don't have access to the container with its mappers for properties. Returning non-simple types eg. DateTime throws an error and you have to access DateTimeMapper directly if you want to use it to encode that value.
I'll probably get this done using beforeEncode and the global container, and making sure I only return simple values in a Map. But this defeats the purpose of having a container, and means I must encode every property and probably any nested lists or objects (which requires the mappers in the container).
I can see up the call stack that there are EncodingContext and DecodingContext objects that would give me access to the container and options. Ideally it would also include the original value, or the originalValue would be passed to the hook.
I propose that EncodingContext/DecodingContext be passed to all the MappingHook methods like this :
abstract class MappingHook {
const MappingHook();
/// Receives the ecoded value before decoding.
Object? beforeDecode(Object? value, DecodingContext context) => value;
/// Receives the decoded value after decoding.
Object? afterDecode(Object? value, Object? originalValue, DecodingContext context) => value;
/// Receives the decoded value before encoding.
Object? beforeEncode(Object? value, EncodingContext context) => value;
/// Receives the encoded value after encoding.
Object? afterEncode(Object? value, Object? originalValue, EncodingContext context) => value;
}