You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-07-09 23:45:32 +02:00
Fix standard compatiblility
Non-nil but empty map with omitempty should be ignored. Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
This commit is contained in:
@ -130,10 +130,28 @@ func (encoder *optionalEncoder) EncodeInterface(val interface{}, stream *Stream)
|
||||
}
|
||||
|
||||
func (encoder *optionalEncoder) IsEmpty(ptr unsafe.Pointer) bool {
|
||||
return *((*unsafe.Pointer)(ptr)) == nil
|
||||
}
|
||||
|
||||
type optionalMapEncoder struct {
|
||||
valueEncoder ValEncoder
|
||||
}
|
||||
|
||||
func (encoder *optionalMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||
if *((*unsafe.Pointer)(ptr)) == nil {
|
||||
return true
|
||||
stream.WriteNil()
|
||||
} else {
|
||||
encoder.valueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (encoder *optionalMapEncoder) EncodeInterface(val interface{}, stream *Stream) {
|
||||
WriteToStream(val, stream, encoder)
|
||||
}
|
||||
|
||||
func (encoder *optionalMapEncoder) IsEmpty(ptr unsafe.Pointer) bool {
|
||||
p := *((*unsafe.Pointer)(ptr))
|
||||
return p == nil || encoder.valueEncoder.IsEmpty(p)
|
||||
}
|
||||
|
||||
type placeholderEncoder struct {
|
||||
|
Reference in New Issue
Block a user