Skip to content

Commit

Permalink
fix: update pkg/util/json (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu327 authored Dec 12, 2022
1 parent f388fda commit 52f2b92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions pkg/util/json/go_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package json

import json "github.com/goccy/go-json"
import (
"github.com/TencentBlueKing/gopkg/conv"
json "github.com/goccy/go-json"
)

var (
// Marshal is exported by gin/json package.
Expand All @@ -41,10 +44,10 @@ func MarshalToString(v interface{}) (string, error) {
return "", err
}

return string(json), nil
return conv.BytesToString(json), nil
}

// UnmarshalFromString is a convenient method to read from string instead of []byte
func UnmarshalFromString(str string, v interface{}) error {
return Unmarshal([]byte(str), v)
return Unmarshal(conv.StringToBytes(str), v)
}
10 changes: 7 additions & 3 deletions pkg/util/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

package json

import "encoding/json"
import (
"encoding/json"

"github.com/TencentBlueKing/gopkg/conv"
)

var (
// Marshal is exported by gin/json package.
Expand All @@ -43,10 +47,10 @@ func MarshalToString(v interface{}) (string, error) {
return "", err
}

return string(json), nil
return conv.BytesToString(json), nil
}

// UnmarshalFromString is a convenient method to read from string instead of []byte
func UnmarshalFromString(str string, v interface{}) error {
return Unmarshal([]byte(str), v)
return Unmarshal(conv.StringToBytes(str), v)
}

0 comments on commit 52f2b92

Please sign in to comment.