computeOperation method
Implementation
@override
MapEntry? computeOperation(Object? json) {
if (json == null) return MapEntry(null, null);
if (json is MapEntry) {
return json;
} else if (json is Pair) {
return json.asMapEntry;
} else if (json is List) {
if (json.isEmpty) {
return null;
} else if (json.length == 1) {
return MapEntry(json[0], null);
} else {
return MapEntry(json[0], json[1]);
}
} else if (json is Map) {
if (json.isEmpty) {
return null;
} else {
var keyName = getParameter(0);
var valName = getParameter(1);
if (keyName == null || valName == null) {
var keys = json.keys.toList();
if (keyName != null) {
keys.remove(keyName);
}
if (valName != null) {
keys.remove(valName);
}
keyName ??= keys.removeAt(0);
valName ??= keys.removeAt(0);
}
var key = _resolveMapValue(json, keyName);
var val = _resolveMapValue(json, valName);
return MapEntry(key, val);
}
} else {
return MapEntry('/', json);
}
}