why gob encode/decode has no ignore field

1,529 views
Skip to first unread message

guo tie

unread,
Apr 2, 2014, 9:33:57 PM4/2/14
to golan...@googlegroups.com
json encode/decode can use `json:"-"` to ignore some field, why gob encode/decode do not have this function?


Volker Dobler

unread,
Apr 3, 2014, 12:49:27 AM4/3/14
to golan...@googlegroups.com
Gob is used to serialize and deserialize whole Go objects. Dropping fields while serializing makes no sense for this use case.

V.

Matt Harden

unread,
Apr 4, 2014, 9:08:47 PM4/4/14
to Volker Dobler, golang-nuts
On Wed, Apr 2, 2014 at 11:49 PM, Volker Dobler <dr.volke...@gmail.com> wrote:
Gob is used to serialize and deserialize whole Go objects. Dropping fields while serializing makes no sense for this use case.
 
I disagree with that. Some objects have fields that are volatile and make no sense to (de)serialize. Gob does not use struct tags, though, and I don't think it should start doing so just to support field hiding. If you don't want a field to be (de)serialized, either don't export it, or implement Gob{En,De}code yourself.

Dan Kortschak

unread,
Apr 4, 2014, 9:15:12 PM4/4/14
to Matt Harden, Volker Dobler, golang-nuts
Or copy the struct and zero the relevant fields in the copy before encoding.
Reply all
Reply to author
Forward
0 new messages