-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
ignore json tag omitempty
, can output empty field
// OmitDefaultExtension 忽略json tag的omitempty
type OmitDefaultExtension struct {
jsoniter.DummyExtension
}
// DecorateEncoder 修饰编码器
func (extension *OmitDefaultExtension) DecorateEncoder(typ reflect2.Type, encoder jsoniter.ValEncoder) jsoniter.ValEncoder {
return omitDefaultEncoder{encoder}
}
type omitDefaultEncoder struct {
jsoniter.ValEncoder
}
func (o omitDefaultEncoder) IsEmpty(ptr unsafe.Pointer) bool {
return false
}
My Question
请问这样实现有问题吗,我试了下是输出是符合要求的,但是不清楚IsEmpty全部返回false有没有副作用。
我搜了下代码IsEmpty,field.encoder.omitempty && field.encoder.IsEmpty(ptr)
只有这样用的,看着应该没有问题,还是想确认下才安心。
Is there any problem with this implementation? I have tried and found that the output meets the requirements, but I am not sure whether IsEmpty returns false or not. I searched the code IsEmpty, 'field.encoder Field. Encoder.IsEmpty(PTR) 'only in this way, look should be no problem, or want to confirm the peace of mind
Metadata
Metadata
Assignees
Labels
No labels