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. 😕
At the moment, all of the
UnrecognizedFieldsfields in serialised objects usemap[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 theanyvalues of the map and then deserialise them into a custom type, which is really quite wasteful). And for themetadata.Rolestypes 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.RawMessagewhich is a fully supported way to let programs delay JSON parsing, and is particularly handy for these kinds of extension usecases. If allUnrecognizedFieldsfields were insteadmap[string]json.RawMessagethen it would be much easier to play with TUF extensions using go-tuf.Unfortunately this would obviously be a breaking change. 😕