in resources/resources.go [173:201]
func (ks KernelSpec) MarshalJSON() ([]byte, error) {
rawFields := make(map[string]any)
for k, v := range ks.rawFields {
rawFields[k] = v
}
if len(ks.ID) > 0 {
rawFields["name"] = ks.ID
}
if ks.Spec != nil {
specBytes, err := json.Marshal(ks.Spec)
if err != nil {
return nil, fmt.Errorf("failure unmarshalling a nested `spec` field: %w", err)
}
specMap := make(map[string]any)
if err := json.Unmarshal(specBytes, &specMap); err != nil {
return nil, fmt.Errorf("failure unmarshalling a nested `spec` field: %w", err)
}
for k, v := range specMap {
if v == nil {
delete(specMap, k)
}
}
rawFields["spec"] = specMap
}
if len(ks.Resources) > 0 {
rawFields["resources"] = ks.Resources
}
return json.Marshal(rawFields)
}