jsonSerializable function
Builder
jsonSerializable(
- BuilderOptions options
Supports package:build_runner creation and configuration of
json_serializable.
Not meant to be invoked by hand-authored code.
Implementation
Builder jsonSerializable(BuilderOptions options) {
try {
var configJson = options.config;
// Ignore `run_only_if_triggered` if present, it's used by `build_runner`.
if (configJson.containsKey('run_only_if_triggered')) {
configJson = Map.of(configJson)..remove('run_only_if_triggered');
}
final config = JsonSerializable.fromJson(configJson);
return jsonPartBuilder(config: config);
} on CheckedFromJsonException catch (e) {
final lines = <String>[
'Could not parse the options provided for `json_serializable`.',
];
if (e.key != null) {
lines.add('There is a problem with "${e.key}".');
}
if (e.message != null) {
lines.add(e.message!);
} else if (e.innerError != null) {
lines.add(e.innerError.toString());
}
throw StateError(lines.join('\n'));
}
}