setByPath<T> method
dynamic
setByPath<T>(
- JsonPath<
T> path, - T? value
inherited
Implementation
dynamic setByPath<T>(JsonPath<T> path, T? value) {
if (value == "") value = null;
final lastSegment = path.last;
final parents = path.chop;
dynamic container = this;
for (var segment in parents.segments) {
container = container.get(segment);
if (container == null) {
throw Exception(
"Missing container in heirarchy. Full path: $path. Error found at segment $segment");
}
}
if (value == null && container is Map) {
container.remove(lastSegment);
} else {
container[lastSegment] = value;
}
}