summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--encode.go4
-rw-r--r--methods_test.go9
2 files changed, 11 insertions, 2 deletions
diff --git a/encode.go b/encode.go
index f93cba4..acef214 100644
--- a/encode.go
+++ b/encode.go
@@ -9,8 +9,10 @@ import (
"encoding"
"encoding/base64"
"encoding/json"
+ "errors"
"fmt"
"io"
+ iofs "io/fs"
"reflect"
"sort"
"strconv"
@@ -130,7 +132,7 @@ func encode(w io.Writer, val reflect.Value, escaper BackslashEscaper, quote bool
SourceFunc: "EncodeJSON",
}})
}
- if err := validator.Close(); err != nil {
+ if err := validator.Close(); err != nil && !errors.Is(err, iofs.ErrClosed) {
panic(encodeError{err})
}
diff --git a/methods_test.go b/methods_test.go
index 8280a94..a74532c 100644
--- a/methods_test.go
+++ b/methods_test.go
@@ -15,10 +15,17 @@ import (
"git.lukeshu.com/go/lowmemjson"
)
+type ShortSum string
+
+func (s ShortSum) EncodeJSON(w io.Writer) error {
+ // Test that it's OK to call lowmemjson.Encode for the top-level value in a method.
+ return lowmemjson.Encode(w, string(s))
+}
+
type SumRun struct {
ChecksumSize int `json:",omitempty"`
Addr int64 `json:",omitempty"`
- Sums string
+ Sums ShortSum
}
type SumRunWithGaps struct {