PolicyResource.fromJson constructor

PolicyResource.fromJson(
  1. String path,
  2. Map<String, dynamic> json
)

Returns a PolicyResource with the path and enriches it with the given information in json.

Throws an InvalidJsonSchemaException if json could not be parsed to valid grant and revoke parameters.

Implementation

factory PolicyResource.fromJson(String path, Map<String, dynamic> json) {
  final PolicyResource pR = PolicyResource(path);
  try {
    if (json.containsKey(DittoKeys.grant)) {
      pR.grant = _createPermissionSet(json[DittoKeys.grant] as List<dynamic>);
    }
    if (json.containsKey(DittoKeys.revoke)) {
      pR.revoke =
          _createPermissionSet(json[DittoKeys.revoke] as List<dynamic>);
    }
  } on TypeError catch (e) {
    throw InvalidJsonSchemaException(
        e.stackTrace.toString(), json.toString());
  }
  return pR;
}