diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/json/compat.go | 11 |
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 } |