better reviver API for JsonDecoder #29750
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
core-n
library-convert
type-enhancement
A request for a change that isn't a bug
The JsonDecoder constructor takes a
reviver
that works much the same way as in JavaScript. However, this isn't useful for decoding protobufs (for example) because it doesn't provide enough context.The type of a protobuf depends on its path from the root, based on JSON map keys. For example, 0->1->2 might be known to be a particular type. The reviver only supplies the last key in the path, which isn't enough to deserialize using a reviver. Instead we construct all the Dart maps and lists for the entire tree, and deserialize it to protobufs as a second pass.
One way to fix would be to add a callback when descending into each map key, so the reviver can maintain a stack.
This API also doesn't declare any types, which means the callback needs to do "is" checks to figure out what's going on. And it also creates maps only to throw them away if you're not reviving a map.
The text was updated successfully, but these errors were encountered: