fromJSON static method
PublicationCollection?
fromJSON(
- dynamic json, {
- LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity,
Parses a PublicationCollection from its RWPM JSON representation.
If the collection can't be parsed, a warning will be logged with warnings
.
The links' href and their children's will be normalized recursively using the
provided normalizeHref
closure.
Implementation
static PublicationCollection? fromJSON(dynamic json,
{LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity}) {
if (json == null) {
return null;
}
List<Link> links;
Map<String, dynamic>? metadata;
Map<String, List<PublicationCollection>>? subcollections;
// Parses a sub-collection object.
if (json is Map<String, dynamic>) {
links = Link.fromJSONArray(json.remove("links") as List<dynamic>?,
normalizeHref: normalizeHref);
metadata = (json.remove("metadata") as Map<String, dynamic>?);
subcollections = collectionsFromJSON(json, normalizeHref: normalizeHref);
}
// Parses an array of links.
else if (json is List) {
links = Link.fromJSONArray(json, normalizeHref: normalizeHref);
} else {
Fimber.i("core collection not valid");
return null;
}
if (links.isEmpty) {
Fimber.i("core collection's [links] must not be empty");
return null;
}
return PublicationCollection(
metadata: metadata ?? {},
links: links,
subcollections: subcollections ?? {});
}