allow invalid utf8 characters when marshalizing json responses

This commit is contained in:
Gani Georgiev committed 2026-08-24 14:13:53 +03:00
1 parent 50f5f83ace
commit 756b326bfa
9 files changed
+57 -20

No files matched your search

+7 -1
View File
@@ -3,6 +3,7 @@ package core
import (
"bytes"
"context"
"encoding/json/jsontext"
"encoding/json/v2"
"errors"
"fmt"
@@ -1329,7 +1330,12 @@ func (record *Record) PublicExport() map[string]any {
//
// Only the data exported by `PublicExport()` will be serialized.
func (m Record) MarshalJSON() ([]byte, error) {
return json.Marshal(m.PublicExport(), json.Deterministic(true))
return json.Marshal(
m.PublicExport(),
json.Deterministic(true),
// to preserve the old jsonv1 behavior in case of invalid data
jsontext.AllowInvalidUTF8(true),
)
}
// UnmarshalJSON implements the [json.Unmarshaler] interface.