Skip to content

better reviver API for JsonDecoder #29750

Open
@skybrian

Description

@skybrian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-nlibrary-converttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions