Conditional Hooks
Closed this issue · 1 comments
Hello!
I am using hooks to prevent sensitive information in certain fields reaching the database. And this works well.
However, I'd like to save the complete serialzied data in a local Hive storage.
I could call myObject.toMap()
but this filters out the sensitive information, which in this case I want to store locally.
I could make the hooks check a global variable to decide on the serialization strategy. But this doesn't feel right.
Another option is to use Hive-annotation to store objects locally. But this results in annotation monsters for two kinds of serializations. Like the one below:
@HiveType(typeId: 0)
@MappableClass()
class Encrypted with EncryptedMappable {
@HiveField(0)
List<int> messageCipher;
@MappableField(hook: EmptyListHook())
@HiveField(1)
List<int> messagePlain;
...
Question
Is there a way to set a switch to disable all hooks when calling toJson()
or toMap()
? I noticed that toString()
does not seem to apply any hooks.
toJson(hooks:false)
I am aware that this is probably out-of scope for this project, but I have to ask.
Thank you!
There is no built-in way to conditionally apply hooks, and also not planned.
Other than using a global variable to toggle this maybe you can use Dart Zones for a cleaner implementation.