Skip to content

Commit

Permalink
Omitempty on JSON decoder (#262)
Browse files Browse the repository at this point in the history
* Update json-decode.go

* Update json-decode.go

Co-Authored-By: fedekunze <[email protected]>
  • Loading branch information
2 people authored and liamsi committed May 2, 2019
1 parent 87ef78b commit fc5dc13
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions json-decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,12 @@ func (cdc *Codec) decodeReflectJSONStruct(bz []byte, info *TypeInfo, rv reflect.
// but perhaps we are aiming for as much compatibility here.
// JAE: I vote we depart from encoding/json, than carry a vuln.

// Set nil/zero on frv.
frv.Set(reflect.Zero(frv.Type()))
// Set to the zero value only if not omitempty
if !field.JSONOmitEmpty {
// Set nil/zero on frv.
frv.Set(reflect.Zero(frv.Type()))
}

continue
}

Expand Down

0 comments on commit fc5dc13

Please sign in to comment.