titan-x / titan

Messaging server with mobile and browser support.
MIT License
2 stars 3 forks source link

Make notes at all levels about serializer/deserializer ignoring private fields on given struct for interface{} types #65

Open soygul opened 8 years ago

soygul commented 8 years ago

Both Neptulon JSON-RPC and Titan types needs multiple document changes in various places about this.

soygul commented 8 years ago

The Go visibility rules for struct fields are amended for JSON when deciding which field to marshal or unmarshal. If there are multiple fields at the same level, and that level is the least nested (and would therefore be the nesting level selected by the usual Go rules), the following extra rules apply:

1) Of those fields, if any are JSON-tagged, only tagged fields are considered, even if there are multiple untagged fields that would otherwise conflict. 2) If there is exactly one field (tagged or not according to the first rule), that is selected. 3) Otherwise there are multiple fields, and all are ignored; no error occurs.

src: http://golang.org/pkg/encoding/json/#Marshal

soygul commented 8 years ago

Example usage:

    type sendMsgReq struct {
        To      string `json:"to"`
        Message string `json:"message"`
    }

        ctx.Params(&s)