simplify method Null safety
- dynamic value
Simplify converts gson results to something you can easily deal with. some of these changes can't be recreated from the results. Also in gson booleans are encoded as bytes and bytes are converted to integers in here, so instead of a true you will probably get 1 and instead of false 0 The results of this method are compatible with the json library, you can encode them as json
Implementation
dynamic simplify(dynamic value) {
if (value is Map<String, dynamic>) {
var map = {};
value.forEach((k, v) {
map[k] = simplify(v);
});
} else if (value is List<dynamic>) {
var list = [];
value.forEach((v) {
list.add(simplify(v));
});
} else if (value is GsonValue) {
return value.toSimple();
} else {
return value;
}
}