feat: add method to jsonx (#2049)

This commit is contained in:
Minghong Fang
2022-07-09 14:20:53 +08:00
committed by GitHub
parent f6f6ee5c8c
commit 48f7e01158
2 changed files with 22 additions and 0 deletions

View File

@@ -85,3 +85,16 @@ func TestUnmarshalFromReaderError(t *testing.T) {
err := UnmarshalFromReader(strings.NewReader(s), &v)
assert.NotNil(t, err)
}
func TestMarshalToString(t *testing.T) {
var v = struct {
Name string `json:"name"`
Age int `json:"age"`
}{
Name: "John",
Age: 30,
}
toString, err := MarshalToString(v)
assert.Nil(t, err)
assert.Equal(t, `{"name":"John","age":30}`, toString)
}