fromJson static method
Subject?
fromJson(
- dynamic json, {
- LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity,
Parses a Subject from its RWPM JSON representation.
A subject can be parsed from a single string, or a full-fledged object.
The links' href and their children's will be normalized recursively using the
provided normalizeHref
closure.
If the subject can't be parsed, a warning will be logged with warnings
.
Implementation
static Subject? fromJson(dynamic json,
{LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity}) {
if (json == null) {
return null;
}
LocalizedString? localizedName;
if (json is String) {
localizedName = LocalizedString.fromJson(json);
} else if (json is Map<String, dynamic>) {
localizedName = LocalizedString.fromJson(json.opt("name"));
}
if (localizedName == null) {
Fimber.i("[name] is required");
return null;
}
Map<String, dynamic> jsonObject =
(json is Map<String, dynamic>) ? json : {};
return Subject(
localizedName: localizedName,
localizedSortAs: LocalizedString.fromJson(jsonObject.remove("sortAs")),
scheme: jsonObject.optNullableString("scheme"),
code: jsonObject.optNullableString("code"),
links: Link.fromJSONArray(jsonObject.optJSONArray("links"),
normalizeHref: normalizeHref));
}