SchemaObject.fromJson constructor

SchemaObject.fromJson(
  1. dynamic jsonObject
)

Implementation

SchemaObject.fromJson(dynamic jsonObject) {
  var map = credentialToMap(jsonObject);
  if (map.containsKey('type')) {
    var t = map['type'];
    switch (t) {
      case 'integer':
        type = DIFSchemaType.integer;
        break;
      case 'string':
        type = DIFSchemaType.string;
        break;
      case 'boolean':
        type = DIFSchemaType.boolean;
        break;
      case 'number':
        type = DIFSchemaType.number;
        break;
      default:
        throw Exception('unknown Schema type');
    }
  } else {
    throw Exception('type property needed in schema object');
  }

  if (type == DIFSchemaType.string) {
    if (map.containsKey('format')) {
      var f = map['format'];
      switch (f) {
        case 'date-time':
          format = StringFormat.dateTime;
          break;
        case 'date':
          format = StringFormat.date;
          break;
        case 'time':
          format = StringFormat.time;
          break;
        case 'email':
          format = StringFormat.email;
          break;
        case 'idn-email':
          format = StringFormat.idnEmail;
          break;
        case 'hostname':
          format = StringFormat.hostname;
          break;
        case 'idn-hostname':
          format = StringFormat.idnHostname;
          break;
        case 'ipv4':
          format = StringFormat.ipv4;
          break;
        case 'ipv6':
          format = StringFormat.ipv6;
          break;
        case 'uri':
          format = StringFormat.uri;
          break;
        case 'uri-reference':
          format = StringFormat.uriReference;
          break;
        case 'iri':
          format = StringFormat.iri;
          break;
        case 'iri-reference':
          format = StringFormat.iriReference;
          break;
        default:
          throw Exception('unknown format value');
      }
    }
  }
}