summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-17 15:19:12 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-17 15:43:38 -0600
commit494ad195bc31ce6a65f759544355801fe357c56d (patch)
treed7c8b5d59626651a446614666ee02f6a3044e439 /compat
parent25f5b3a2aabe11a7f8dad3d001ac30b65c1e6c06 (diff)
Add more tests around trailing-newlines from the encoder
Diffstat (limited to 'compat')
-rw-r--r--compat/json/compat.go11
1 files changed, 3 insertions, 8 deletions
diff --git a/compat/json/compat.go b/compat/json/compat.go
index 8dcb266..42dd807 100644
--- a/compat/json/compat.go
+++ b/compat/json/compat.go
@@ -71,7 +71,7 @@ func Marshal(v any) ([]byte, error) {
}
type Encoder struct {
- encoder lowmemjson.Encoder
+ encoder *lowmemjson.Encoder
formatter lowmemjson.ReEncoder
}
@@ -86,16 +86,12 @@ func NewEncoder(w io.Writer) *Encoder {
ForceTrailingNewlines: true,
},
}
- ret.encoder.W = &ret.formatter
+ ret.encoder = lowmemjson.NewEncoder(&ret.formatter)
return ret
}
func (enc *Encoder) Encode(v any) error {
- err := enc.encoder.Encode(v)
- if err == nil {
- err = enc.formatter.Close()
- }
- return convertEncodeError(err)
+ return convertEncodeError(enc.encoder.Encode(v))
}
func (enc *Encoder) SetEscapeHTML(on bool) {
@@ -103,7 +99,6 @@ func (enc *Encoder) SetEscapeHTML(on bool) {
if !on {
escaper = lowmemjson.EscapeDefaultNonHTMLSafe
}
- enc.encoder.BackslashEscape = escaper
enc.formatter.BackslashEscape = escaper
}