Serialize nil slices as empty slices
This commit is contained in:
parent
810a13cee0
commit
ee9a355613
1 changed files with 5 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue