fromEntry static method

Node fromEntry(
  1. Container container,
  2. MapEntry<String, dynamic> entry
)

Try to create a Node instance of corresponding type

Implementation

static Node fromEntry(Container container, MapEntry<String, dynamic> entry) {
    if (validName(entry.key) == '') throw Exception('Node "${entry.key}" in ${container.filename}.json is resulted with the name parsed into an empty string.');
    if (entry.value is Map) return Object(container, entry.key, entry.value as Map<String, dynamic>);
    if (entry.value is List) {
        final List<dynamic> value = entry.value as List<dynamic>;
        if (value.length == 1 && value[0] is Map) return Message(container, entry.key, value);
        if (value.length == 2 && value[0] is Map && value[1] is Map) return Request(container, entry.key, value);
        if (value.fold(value.isNotEmpty, (bool a, dynamic b) => a && (b is String))) return Enum(container, entry.key, value);
    }
    throw Exception('Node "${entry.key}" in ${container.filename}.json has invalid format. Use array of strings for enum declaration, object for object declaration or array of 1 or 2 objects for message or request correspondingly.');
}