Link.parse constructor

Link.parse(
  1. Map json
)

Implementation

factory Link.parse(Map json) {
  String? href = json["href"];
  if (href == null) {
    throw LcpException.parsing.link;
  }
  dynamic rel = json["rel"];
  List<String> relations = [];
  if (rel is String) {
    relations.add(rel);
  } else if (rel is Iterable<String>) {
    relations.addAll(rel);
  }
  if (relations.isEmpty) {
    throw LcpException.parsing.link;
  }
  return Link._(
      href,
      relations,
      json["title"] as String,
      json["type"] as String,
      json["templated"] as bool? ?? false,
      (json["profile"] != null) ? Uri.parse(json["profile"]) : null,
      json["length"] as int? ?? 0,
      json["hash"] as String?);
}