diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lowmemjson/encode.go | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/lowmemjson/encode.go b/lib/lowmemjson/encode.go index 329f6c2..107b4da 100644 --- a/lib/lowmemjson/encode.go +++ b/lib/lowmemjson/encode.go @@ -189,20 +189,13 @@ func encode(w io.Writer, val reflect.Value, quote bool) { case reflect.Struct: encodeWriteByte(w, '{') empty := true - nextStructField: for _, field := range indexStruct(val.Type()) { - fVal := val - for _, idx := range field.Path { - if fVal.Kind() == reflect.Pointer { - if fVal.IsNil() { - continue nextStructField - } - fVal = fVal.Elem() - } - fVal = fVal.Field(idx) + fVal, err := val.FieldByIndexErr(field.Path) + if err != nil { + continue } if field.OmitEmpty && isEmptyValue(fVal) { - continue nextStructField + continue } if !empty { encodeWriteByte(w, ',') |