You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	fix #311 handle nil any
This commit is contained in:
		
							
								
								
									
										4
									
								
								any.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								any.go
									
									
									
									
									
								
							| @@ -312,6 +312,10 @@ func (codec *directAnyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||||
|  | ||||
| func (codec *directAnyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||||
| 	any := *(*Any)(ptr) | ||||
| 	if any == nil { | ||||
| 		stream.WriteNil() | ||||
| 		return | ||||
| 	} | ||||
| 	any.WriteTo(stream) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -224,3 +224,13 @@ func Test_EmptyInput(t *testing.T) { | ||||
| 		t.Errorf("Expected error") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type Foo struct { | ||||
| 	A jsoniter.Any | ||||
| } | ||||
|  | ||||
| func Test_nil_any(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	data, _ := jsoniter.Marshal(&Foo{}) | ||||
| 	should.Equal(`{"A":null}`, string(data)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user