Open alonbg opened 3 years ago
Trying to get an omitempty behavior for all fields of a bunch of third party well nested structs. getting empty values instead.
omitempty
type omitemptyExtension struct { jsoniter.DummyExtension } type omitemptyEncoder struct { encoder jsoniter.ValEncoder } func (o *omitemptyEncoder) IsEmpty(ptr unsafe.Pointer) bool { return o.encoder.IsEmpty(ptr) } func (o *omitemptyEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { if o.IsEmpty(ptr) { return } o.encoder.Encode(ptr, stream) } func (ext *omitemptyExtension) DecorateEncoder(typ reflect2.Type, encoder jsoniter.ValEncoder) jsoniter.ValEncoder { return &omitemptyEncoder{ encoder: encoder, } }
If binding.Encoder.(*structFieldEncoder).omitempty was changeable, I assume then, it could have been modified via UpdateStructDescriptor(structDescriptor *StructDescriptor) (i.e. binding.Encoder.(*structFieldEncoder).OmitEmpty(true) )
binding.Encoder.(*structFieldEncoder).omitempty
UpdateStructDescriptor(structDescriptor *StructDescriptor)
binding.Encoder.(*structFieldEncoder).OmitEmpty(true)
Trying to get an
omitempty
behavior for all fields of a bunch of third party well nested structs. getting empty values instead.If
binding.Encoder.(*structFieldEncoder).omitempty
was changeable, I assume then, it could have been modified viaUpdateStructDescriptor(structDescriptor *StructDescriptor)
(i.e.binding.Encoder.(*structFieldEncoder).OmitEmpty(true)
)