deps: remove problematic sonic json library

This commit is contained in:
yusing
2025-04-25 19:09:27 +08:00
parent 759995972d
commit 9e4aa32120
5 changed files with 32 additions and 75 deletions

View File

@@ -1,14 +0,0 @@
package expect
import (
"github.com/bytedance/sonic"
"github.com/yusing/go-proxy/internal/common"
)
func init() {
if common.IsTest {
sonic.ConfigDefault = sonic.Config{
SortMapKeys: true,
}.Froze()
}
}

View File

@@ -1,22 +1,17 @@
package trie
import (
"encoding/json"
"maps"
"github.com/bytedance/sonic"
)
var sonicConfig = sonic.Config{
EncodeNullForInfOrNan: true,
}.Froze()
func (r *Root) MarshalJSON() ([]byte, error) {
return sonicConfig.Marshal(maps.Collect(r.Walk))
return json.Marshal(maps.Collect(r.Walk))
}
func (r *Root) UnmarshalJSON(data []byte) error {
var m map[string]any
if err := sonicConfig.Unmarshal(data, &m); err != nil {
if err := json.Unmarshal(data, &m); err != nil {
return err
}
for k, v := range m {

View File

@@ -1,9 +1,8 @@
package trie
import (
"encoding/json"
"testing"
"github.com/bytedance/sonic"
)
func TestMarshalUnmarshalJSON(t *testing.T) {
@@ -18,14 +17,14 @@ func TestMarshalUnmarshalJSON(t *testing.T) {
}
// MarshalJSON
bytesFromTrie, err := sonic.Marshal(trie)
bytesFromTrie, err := json.Marshal(trie)
if err != nil {
t.Fatalf("sonic.Marshal error: %v", err)
t.Fatalf("json.Marshal error: %v", err)
}
// UnmarshalJSON
newTrie := NewTrie()
if err := sonic.Unmarshal(bytesFromTrie, newTrie); err != nil {
if err := json.Unmarshal(bytesFromTrie, newTrie); err != nil {
t.Fatalf("UnmarshalJSON error: %v", err)
}
for k, v := range data {