ContextRoot.fromJson constructor

ContextRoot.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json, {
  4. ClientUriConverter? clientUriConverter,
})

Implementation

factory ContextRoot.fromJson(
    JsonDecoder jsonDecoder, String jsonPath, Object? json,
    {ClientUriConverter? clientUriConverter}) {
  json ??= {};
  if (json is Map) {
    String root;
    if (json.containsKey('root')) {
      root = clientUriConverter?.fromClientFilePath(
              jsonDecoder.decodeString('$jsonPath.root', json['root'])) ??
          jsonDecoder.decodeString('$jsonPath.root', json['root']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'root');
    }
    List<String> exclude;
    if (json.containsKey('exclude')) {
      exclude = jsonDecoder.decodeList(
          '$jsonPath.exclude',
          json['exclude'],
          (String jsonPath, Object? json) =>
              clientUriConverter?.fromClientFilePath(
                  jsonDecoder.decodeString(jsonPath, json)) ??
              jsonDecoder.decodeString(jsonPath, json));
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'exclude');
    }
    String? optionsFile;
    if (json.containsKey('optionsFile')) {
      optionsFile = clientUriConverter?.fromClientFilePath(jsonDecoder
              .decodeString('$jsonPath.optionsFile', json['optionsFile'])) ??
          jsonDecoder.decodeString(
              '$jsonPath.optionsFile', json['optionsFile']);
    }
    return ContextRoot(root, exclude, optionsFile: optionsFile);
  } else {
    throw jsonDecoder.mismatch(jsonPath, 'ContextRoot', json);
  }
}