collectionsFromJSON static method
Map<String, List<PublicationCollection> >
collectionsFromJSON(
- Map<
String, dynamic> json, { - LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity,
Parses a map of PublicationCollection indexed by their roles 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 Map<String, List<PublicationCollection>> collectionsFromJSON(
Map<String, dynamic> json,
{LinkHrefNormalizer normalizeHref = linkHrefNormalizerIdentity}) {
Map<String, List<PublicationCollection>> collections = {};
for (String role in json.keys.toList()..sort((a, b) => a.compareTo(b))) {
dynamic subJSON = json[role];
// Parses a list of links or a single collection object.
PublicationCollection? collection =
PublicationCollection.fromJSON(subJSON, normalizeHref: normalizeHref);
if (collection != null) {
collections.putIfAbsent(role, () => []).add(collection);
// Parses a list of collection objects.
} else if (subJSON is List) {
Iterable<PublicationCollection> subcollections = subJSON
.map((it) => PublicationCollection.fromJSON(it,
normalizeHref: normalizeHref))
.whereNotNull();
collections.putIfAbsent(role, () => []).addAll(subcollections);
}
}
return collections;
}