Only invoke the standard JSON encoder if there is actually something to encode; otherwise write JSON null literal directly.
(obj interface{})
| 165 | // Only invoke the standard JSON encoder if there is actually something to |
| 166 | // encode; otherwise write JSON null literal directly. |
| 167 | func (enc *jsonEncoder) encodeReflected(obj interface{}) ([]byte, error) { |
| 168 | if obj == nil { |
| 169 | return nullLiteralBytes, nil |
| 170 | } |
| 171 | enc.resetReflectBuf() |
| 172 | if err := enc.reflectEnc.Encode(obj); err != nil { |
| 173 | return nil, err |
| 174 | } |
| 175 | enc.reflectBuf.TrimNewline() |
| 176 | return enc.reflectBuf.Bytes(), nil |
| 177 | } |
| 178 | |
| 179 | func (enc *jsonEncoder) AddReflected(key string, obj interface{}) error { |
| 180 | valueBytes, err := enc.encodeReflected(obj) |
no test coverage detected