From 5ed96f28696c99eb198483b6f92db2fa00ae6d7b Mon Sep 17 00:00:00 2001 From: Bo Du Date: Mon, 11 Feb 2019 17:11:56 -0500 Subject: [PATCH] Return JSON marshallable empty response. --- query/grouped_result.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/query/grouped_result.go b/query/grouped_result.go index 95c3bd5..f3ebd16 100644 --- a/query/grouped_result.go +++ b/query/grouped_result.go @@ -35,6 +35,10 @@ const ( defaultTrimTriggerSizeMultiplier = 4 ) +var ( + emptyJSONResponse = []byte("{}") +) + // GroupedResults is a collection of result groups. type GroupedResults struct { // GroupBy contains a list of field paths to group results by. @@ -175,7 +179,7 @@ func (r *GroupedResults) TrimIfNeeded() { // MarshalJSON marshals the grouped results as a JSON object. func (r *GroupedResults) MarshalJSON() ([]byte, error) { if r.IsEmpty() { - return nil, nil + return emptyJSONResponse, nil } var ( limit = r.Limit