1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-30 23:23:49 +02:00

#164 support interface{} with ptr

This commit is contained in:
Tao Wen
2017-09-09 08:45:57 +08:00
parent 8c7fc7584a
commit 0828e559d0
2 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"
"testing"
"unsafe"
"fmt"
)
func Test_write_array_of_interface(t *testing.T) {
@ -297,3 +298,18 @@ func Test_array_with_nothing(t *testing.T) {
should.Nil(err)
should.Equal(`[null,null]`, output)
}
func Test_unmarshal_ptr_to_interface(t *testing.T) {
type TestData struct {
Name string `json:"name"`
}
should := require.New(t)
var obj interface{} = &TestData{}
err := json.Unmarshal([]byte(`{"name":"value"}`), &obj)
should.Nil(err)
should.Equal("&{value}", fmt.Sprintf("%v", obj))
obj = interface{}(&TestData{})
err = Unmarshal([]byte(`{"name":"value"}`), &obj)
should.Nil(err)
should.Equal("&{value}", fmt.Sprintf("%v", obj))
}