WorldTouchpoint.fromJson constructor
WorldTouchpoint.fromJson(
- Map<String, dynamic> json
)
Implementation
factory WorldTouchpoint.fromJson(Map<String, dynamic> json) {
final name = json['name'] as String?;
if (name == null || name.isEmpty) {
throw const WorldManifestError(
'touchpoint without a name --> fix: every touchpoints[] entry '
'needs a non-empty "name".',
);
}
final contract = json['contract'] as String? ?? '';
final methods = (json['methods'] as List? ?? const [])
.map(
(m) => ContractMethod.fromJson(Map<String, dynamic>.from(m as Map)),
)
.toList(growable: false);
if (methods.isEmpty) {
throw WorldManifestError(
'touchpoint "$name" declares no contract methods '
'--> fix: parse the contract first or declare methods[] — a '
'world touchpoint without methods has no contract to satisfy.',
);
}
return WorldTouchpoint(
name: name,
type: json['type'] as String? ?? 'service',
family: json['family'] as String? ?? 'generic',
priority: json['priority'] as String? ?? 'P2',
contract: contract,
methods: methods,
);
}