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

Method ObjectKeyOmitEmpty

encode_object.go:304–333  ·  view source on GitHub ↗

ObjectKeyOmitEmpty 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

(key string, v MarshalerJSONObject)

Source from the content-addressed store, hash-verified

302// Must be used inside a slice or array encoding (does not encode a key)
303// value must implement MarshalerJSONObject
304func (enc *Encoder) ObjectKeyOmitEmpty(key string, v MarshalerJSONObject) {
305 if enc.hasKeys {
306 if !enc.keyExists(key) {
307 return
308 }
309 }
310 if v.IsNil() {
311 return
312 }
313 enc.grow(5 + len(key))
314 r := enc.getPreviousRune()
315 if r != '{' {
316 enc.writeByte(',')
317 }
318 enc.writeByte('"')
319 enc.writeStringEscape(key)
320 enc.writeBytes(objKeyObj)
321
322 var origHasKeys = enc.hasKeys
323 var origKeys = enc.keys
324 enc.hasKeys = false
325 enc.keys = nil
326
327 v.MarshalJSONObject(enc)
328
329 enc.hasKeys = origHasKeys
330 enc.keys = origKeys
331
332 enc.writeByte('}')
333}
334
335// ObjectKeyNullEmpty adds an object to be encoded or skips it if IsNil returns true.
336// Must be used inside a slice or array encoding (does not encode a key)

Callers 2

AddObjectKeyOmitEmptyMethod · 0.95
MarshalJSONObjectMethod · 0.80

Calls 8

keyExistsMethod · 0.95
growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
writeStringEscapeMethod · 0.95
writeBytesMethod · 0.95
IsNilMethod · 0.65
MarshalJSONObjectMethod · 0.65

Tested by 1

MarshalJSONObjectMethod · 0.64