1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00

customize []byte encoder

This commit is contained in:
Tao Wen 2017-05-06 20:52:36 +08:00
parent b893a0359d
commit 1df353727b

View File

@ -43,6 +43,19 @@ func Test_customize_type_encoder(t *testing.T) {
should.Equal(`"1970-01-01 00:00:00"`, str)
}
func Test_customize_byte_array_encoder(t *testing.T) {
should := require.New(t)
RegisterTypeEncoder("[]uint8", func(ptr unsafe.Pointer, stream *Stream) {
t := *((*[]byte)(ptr))
stream.WriteString(string(t))
})
defer CleanEncoders()
val := []byte("abc")
str, err := MarshalToString(val)
should.Nil(err)
should.Equal(`"abc"`, str)
}
type Tom struct {
field1 string
}