MCPcopy
hub / github.com/pquerna/ffjson / getField

Function getField

inception/encoder.go:434–472  ·  view source on GitHub ↗
(ic *Inception, f *StructField, prefix string)

Source from the content-addressed store, hash-verified

432}
433
434func getField(ic *Inception, f *StructField, prefix string) string {
435 out := ""
436 if f.OmitEmpty {
437 out += ic.q.Flush()
438 if f.Pointer {
439 out += "if " + prefix + f.Name + " != nil {" + "\n"
440 }
441 out += getOmitEmpty(ic, f)
442 }
443
444 if f.Pointer && !f.OmitEmpty {
445 // Pointer values encode as the value pointed to. A nil pointer encodes as the null JSON object.
446 out += "if " + prefix + f.Name + " != nil {" + "\n"
447 }
448
449 // JsonName is already escaped and quoted.
450 // getInnervalue should flush
451 ic.q.Write(f.JsonName + ":")
452 // We save a copy in case we need it
453 t := ic.q
454
455 out += getValue(ic, f, prefix)
456 ic.q.Write(",")
457
458 if f.Pointer && !f.OmitEmpty {
459 out += "} else {" + "\n"
460 out += t.WriteFlush("null")
461 out += "}" + "\n"
462 }
463
464 if f.OmitEmpty {
465 out += ic.q.Flush()
466 if f.Pointer {
467 out += "}" + "\n"
468 }
469 out += "}" + "\n"
470 }
471 return out
472}
473
474// We check if the last field is conditional.
475func lastConditional(fields []*StructField) bool {

Callers 2

getGetInnerValueFunction · 0.85
CreateMarshalJSONFunction · 0.85

Calls 5

getOmitEmptyFunction · 0.85
getValueFunction · 0.85
FlushMethod · 0.80
WriteFlushMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…