francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 113 forks source link

Return error on unknown object key #161

Open bramp opened 3 years ago

bramp commented 3 years ago

I would like the gojay codegen tool to have a flag to return a error if an unknown field is encountered.

For example

func (m *Message) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
    switch k {
    case "type":
        return dec.String(&m.Type)

    case "message":
        return dec.String(&m.Message)

        /////// New code
        default:
        return errUnknownField
    }
    //////
}