(ic *Inception, f *StructField, prefix string)
| 432 | } |
| 433 | |
| 434 | func 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. |
| 475 | func lastConditional(fields []*StructField) bool { |
no test coverage detected
searching dependent graphs…