InputDescriptorField.fromJson constructor

InputDescriptorField.fromJson(
  1. dynamic fieldJson
)

Implementation

InputDescriptorField.fromJson(dynamic fieldJson) {
  var field = credentialToMap(fieldJson);
  if (field.containsKey('path')) {
    List pathString = field['path'];
    path = [];
    for (var p in pathString) {
      path.add(JsonPath(p));
    }
  } else {
    throw FormatException('InputDescriptor need path property');
  }

  if (field.containsKey('id')) id = field['id'];
  if (field.containsKey('purpose')) purpose = field['purpose'];
  if (field.containsKey('name')) name = field['name'];
  if (field.containsKey('filter')) {
    filter = JsonSchema.create(field['filter']);
  }
  if (field.containsKey('optional')) optional = field['optional'];
  if (field.containsKey('predicate')) {
    String p = field['predicate'];
    if (p == 'preferred') {
      predicate = Limiting.preferred;
    } else if (p == 'required') {
      predicate = Limiting.required;
    } else {
      throw Exception('Unknown value for predicate');
    }
  }
}