pquerna / ffjson

faster JSON serialization for Go
Apache License 2.0
2.97k stars 234 forks source link

ffjson generates invalid json #231

Closed nkovacs closed 7 years ago

nkovacs commented 7 years ago

ffjson generates this code for a struct that has a field Events []*Event:

    buf.WriteString(`,"events":`)
    if j.Events != nil {
        buf.WriteString(`[`)
        for i, v := range j.Events {
            if i != 0 {
                buf.WriteString(`,`)
            }

            {

                if v == nil {
                    buf.WriteString("null")
                    return nil
                }

                err = v.MarshalJSONBuf(buf)
                if err != nil {
                    return err
                }

            }
        }
        buf.WriteString(`]`)
    } else {
        buf.WriteString(`null`)
    }

That return nil after writing out null should not be there.