MCPcopy Create free account
hub / github.com/francoispqt/gojay / ObjectOmitEmpty

Method ObjectOmitEmpty

encode_object.go:169–191  ·  view source on GitHub ↗

ObjectOmitEmpty adds an object to be encoded or skips it if IsNil returns true. Must be used inside a slice or array encoding (does not encode a key) value must implement MarshalerJSONObject

(v MarshalerJSONObject)

Source from the content-addressed store, hash-verified

167// Must be used inside a slice or array encoding (does not encode a key)
168// value must implement MarshalerJSONObject
169func (enc *Encoder) ObjectOmitEmpty(v MarshalerJSONObject) {
170 if v.IsNil() {
171 return
172 }
173 enc.grow(2)
174 r := enc.getPreviousRune()
175 if r != '[' {
176 enc.writeByte(',')
177 }
178 enc.writeByte('{')
179
180 var origHasKeys = enc.hasKeys
181 var origKeys = enc.keys
182 enc.hasKeys = false
183 enc.keys = nil
184
185 v.MarshalJSONObject(enc)
186
187 enc.hasKeys = origHasKeys
188 enc.keys = origKeys
189
190 enc.writeByte('}')
191}
192
193// ObjectNullEmpty adds an object to be encoded or skips it if IsNil returns true.
194// Must be used inside a slice or array encoding (does not encode a key)

Callers 1

AddObjectOmitEmptyMethod · 0.95

Calls 5

growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
IsNilMethod · 0.65
MarshalJSONObjectMethod · 0.65

Tested by

no test coverage detected