fromJSON static method
Link?
fromJSON(
- Map<
String, dynamic> ? json, { - LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity,
Creates an Link from its RWPM JSON representation.
It's href and its children's recursively will be normalized using the provided
normalizeHref
closure.
If the link can't be parsed, a warning will be logged with warnings
.
Implementation
static Link? fromJSON(Map<String, dynamic>? json,
{LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity}) {
String? href = json?.optNullableString("href");
if (href == null) {
Fimber.i("[href] is required: $json");
return null;
}
return Link(
href: normalizeHref(href),
type: json.optNullableString("type"),
templated: json.optBoolean("templated", fallback: false),
title: json.optNullableString("title"),
rels: json.optStringsFromArrayOrSingle("rel").toSet(),
properties: Properties.fromJSON(json.optJSONObject("properties")),
height: json.optPositiveInt("height"),
width: json.optPositiveInt("width"),
bitrate: json.optPositiveDouble("bitrate"),
duration: json.optPositiveDouble("duration"),
languages: json.optStringsFromArrayOrSingle("language"),
alternates: fromJSONArray(json.optJSONArray("alternate"),
normalizeHref: normalizeHref),
children: fromJSONArray(json.optJSONArray("children"),
normalizeHref: normalizeHref));
}