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) {
    throw jsonDecoder.mismatch(jsonPath, "'ContextRoot'", json);
  }
  String root;
  if (json case {'root': var encodedRoot}) {
    root =
        clientUriConverter?.fromClientFilePath(
          jsonDecoder.decodeString('$jsonPath.root', encodedRoot),
        ) ??
        jsonDecoder.decodeString('$jsonPath.root', encodedRoot);
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'root'", json);
  }
  List<String> exclude;
  if (json case {'exclude': var encodedExclude}) {
    exclude = jsonDecoder.decodeList(
      '$jsonPath.exclude',
      encodedExclude,
      (String jsonPath, Object? json) =>
          clientUriConverter?.fromClientFilePath(
            jsonDecoder.decodeString(jsonPath, json),
          ) ??
          jsonDecoder.decodeString(jsonPath, json),
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'exclude'", json);
  }
  String? optionsFile;
  if (json case {'optionsFile': var encodedOptionsFile}) {
    optionsFile =
        clientUriConverter?.fromClientFilePath(
          jsonDecoder.decodeString(
            '$jsonPath.optionsFile',
            encodedOptionsFile,
          ),
        ) ??
        jsonDecoder.decodeString('$jsonPath.optionsFile', encodedOptionsFile);
  }
  return ContextRoot(root, exclude, optionsFile: optionsFile);
}