Skip to content

RFE: use json.RawMessage for all UnrecognizedFields maps #724

Description

@cyphar

At the moment, all of the UnrecognizedFields fields in serialised objects use map[string]any. This makes it much more annoying to work with custom types (the only truly type-safe way to do it is to re-serialise the any values of the map and then deserialise them into a custom type, which is really quite wasteful). And for the metadata.Roles types there is no way out of it because you cannot define a wrapping type without breaking some users of the signed wrappers (i.e., metadata.Metadata[T]).

The more standard mechanism to use is json.RawMessage which is a fully supported way to let programs delay JSON parsing, and is particularly handy for these kinds of extension usecases. If all UnrecognizedFields fields were instead map[string]json.RawMessage then it would be much easier to play with TUF extensions using go-tuf.

Unfortunately this would obviously be a breaking change. 😕

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions