1
0
mirror of https://github.com/json-iterator/go.git synced 2025-12-14 23:26:03 +02:00

support map of interface{}

This commit is contained in:
Tao Wen
2017-01-25 22:43:57 +08:00
parent 94ae645ab9
commit f1c4dbde29
8 changed files with 193 additions and 7 deletions

View File

@@ -11,4 +11,32 @@ func Test_write_array_of_interface(t *testing.T) {
str, err := MarshalToString(array)
should.Nil(err)
should.Equal(`["hello"]`, str)
}
func Test_write_map_of_interface(t *testing.T) {
should := require.New(t)
val := map[string]interface{}{"hello":"world"}
str, err := MarshalToString(val)
should.Nil(err)
should.Equal(`{"hello":"world"}`, str)
}
type MyInterface interface {
}
func Test_write_map_of_custom_interface(t *testing.T) {
should := require.New(t)
val := map[string]MyInterface{"hello":"world"}
str, err := MarshalToString(val)
should.Nil(err)
should.Equal(`{"hello":"world"}`, str)
}
func Test_write_interface(t *testing.T) {
should := require.New(t)
var val interface{}
val = "hello"
str, err := MarshalToString(val)
should.Nil(err)
should.Equal(`"hello"`, str)
}