-
Type: Improvement
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
Labels:None
We continue to see evidence of confused users who try to unmarshal into a struct like this:
type Foo struct { bar string `bson:"bar"` baz bool `bson:"baz"` }
Perhaps we should consider returning an error, ErrNoExportedFields, if a user tries to unmarshal into such a struct. It deviates from the json package's behavior, but it does seem like a not-uncommon and very frustrating new user experience, so maybe it's worth it to get users to realize their error quickly (and avoid them needing to go to SO or the mailing list or Jira to ask what's wrong).
By contrast, a struct with mixed exported and unexported fields implies the user is at least thinking about visibility and if they try to unmarshal into that and it doesn't do what they expect, they probably understand visibility enough to figure it out. (Plus we can't error in that case the way we can if there are no exported fields.)