You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	customize []byte encoder
This commit is contained in:
		| @@ -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 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user