Serialize nil slices as empty slices

This commit is contained in:
Eli Ribble 2026-04-21 21:55:48 +00:00
parent 810a13cee0
commit ee9a355613
No known key found for this signature in database

View file

@ -115,7 +115,11 @@ func authenticatedHandlerJSONSlice[T any](f handlerFunctionGetSliceAuthenticated
respondErrorStatus(w, e)
return
}
body, err = json.Marshal(resp)
if resp == nil {
body, err = json.Marshal([]struct{}{})
} else {
body, err = json.Marshal(resp)
}
if err != nil {
respondErrorStatus(w, nhttp.NewError("failed to marshal json: %w", err))
return