BackupJsonExtension<K, T> extension
Extension providing JSON backup and restore capabilities for BoxInterface.
This extension enables any BoxInterface implementation to export its contents as a JSON string and to restore its state from such a JSON backup. This is useful for data migration, backup, and interoperability with other systems.
Example
// Export box contents to JSON
final json = await box.generateBackupJson(
keyToString: (key) => key.toString(),
valueToJson: (value) => value.toJson(),
);
// Restore box contents from JSON
await box.restoreBackupJson(
json,
stringToKey: (str) => int.parse(str),
jsonToValue: (json) => MyModel.fromJson(json),
);
- on
-
- BoxInterface<
K, T>
- BoxInterface<
Methods
-
generateBackupJson(
{String keyToString(K key)?, Object? valueToJson(T value)?}) → Future< String> -
Available on BoxInterface<
Generates a JSON string representing all key-value pairs in the box.K, T> , provided by the BackupJsonExtension extension -
restoreBackupJson(
String json, {required K stringToKey(String key), required T jsonToValue(dynamic json)}) → Future< void> -
Available on BoxInterface<
Restores the box contents from a JSON string backup.K, T> , provided by the BackupJsonExtension extension