jsonapi
jsonapi copied to clipboard
Appending, type-friendlier version of MarshalInclude
Is your feature request related to a problem? Please describe.
With some code I need to build the list of included resources from multiple different types, extracted from multiple different fields. Currently MarshalInclude only accepts an ...any, and only accepts one set of resources that replaces the old set.
Describe the solution you'd like
I would prefer e.g.
func MarshalInclude[T any](v ...T) MarshalOption {
return func(m *Marshaler) {
for _, x := range v {
m.included = append(m.included, x)
}
}
}
(Plus whatever slice capacity performance optimization you may want to complicate that with.)
Either as a direct replacement (which would be an incompatible but for me welcome change), or an alternate version named something like MarshalIncludeAppend.
Describe alternatives you've considered
I think I can't implement my own option here because m.included is private.