New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/json: struct tags to ignore fields don't work on unexported fields #4660
Labels
Milestone
Comments
I am inclined to say that the Go 1.0.3 behavior is correct and that the only regression here is the `json:"-"` being incorrectly ignored at tip. One could argue for ignoring the unexported fields entirely, but then people ask why Unmarshal is silently doing nothing. I think the error does help most people. Labels changed: added priority-later, removed priority-triage. |
That's a bit unfortunate, in that you can then never safely unmarshal into a struct containing unexported fields if you can't be certain the input will never contain those field names in the future. I just had a split a type into two because of this. Oh well. At least this works: type TInner struct { Name string } type T struct { TInner m map[string]interface{} m2 map[string]interface{} } func main() { input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}}` var t T err := json.Unmarshal([]byte(input), &t.TInner) log.Printf("Name %q; err: %v", t.Name, err) } |
Fixed by https://golang.org/cl/7139049/ |
This issue was closed by revision 6e3f3af. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: