marshalJSON marshals a list of fields and their values into JSON. It supports inlined extensions.
(fields []jsonFieldInfo, extensions map[string]any)
| 75 | // marshalJSON marshals a list of fields and their values into JSON. It supports |
| 76 | // inlined extensions. |
| 77 | func marshalJSON(fields []jsonFieldInfo, extensions map[string]any) ([]byte, error) { |
| 78 | value := make(map[string]any, len(extensions)+len(fields)) |
| 79 | |
| 80 | for _, v := range fields { |
| 81 | if v.omit == omitNil && isNilValue(v.value) { |
| 82 | continue |
| 83 | } |
| 84 | if v.omit == omitEmpty { |
| 85 | if isEmptyValue(reflect.ValueOf(v.value)) { |
| 86 | continue |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | value[v.name] = v.value |
| 91 | } |
| 92 | |
| 93 | maps.Copy(value, extensions) |
| 94 | |
| 95 | return json.Marshal(value) |
| 96 | } |
| 97 | |
| 98 | // Contact information to get support for the API. |
| 99 | // |
no test coverage detected
searching dependent graphs…