pquerna / ffjson

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

Issue with boolean custom types in generated ffjson file #264

Open acabarbaye opened 3 years ago

acabarbaye commented 3 years ago

As per my API definition, I have defined some custom types which actually are booleans: e.g.

type EmbedParam bool

in the generated code, I get

    var tval bool

    if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {

        tval = true

    } else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {

        tval = false

    } else {
        err = errors.New("unexpected bytes for true/false value")
        return fs.WrapErr(err)
    }

    j.Embed = &tval

tval is defined as a bool instead of EmbedParam like Embed, meaning I get the following compilation error:

.\****_ffjson.go:***:12: cannot use &tval (type *bool) as type *EmbedParam in assignment

Could the local variable be defined using the custom type i.e. var tval EmbedParam?