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: would like more tags #2514
Labels
Comments
Comment 2 by ultrotter@google.com: Agreed about not having it super-complex. But at the same time it's useful if I can just declare once what I expect and have it parsed, rather than having to check later all the time that the required fields are indeed present. Thanks, Guido |
Comment 3 by ultrotter@google.com: q) would you consider some method that Unmarshal could call on an object if the object supports it, and that would allow it to do more check/personalization in the parsing? Thanks, Guido |
I'd love to toss in a +1 for a `,permitnull` option. The permitnull option would substitute null for the zero value of a given type. I.e., if you have a field declared thusly: Url string `json:"url,permitnull"` and you receive null in some json input, it is unmarshaled to an empty string. https://dev.twitter.com/docs/api/1.1/get/users/lookup is a good example of what I'm talking about: they have fields that should be string that return null instead of just leaving the key off or returning the empty string. of course, once you use ",permitnull", you'll be unmarshalling null into empty string, and then marshaling it back to empty string instead of null, so it's a consistency breaker. Since it's opt-in, I find this to be an acceptable risk, but I could see why it may be decided that this is not acceptable and prevents any such ",permitnull" option from ever appearing. there's also the "just use *string" argument, but I'm wary of having structs with a large number of *string fields in an exported interface. |
Comment 7 by ultrotter@google.com: Note that you could explicitly say whether you want a "zero" field to be encoded or left out as well, to solve that problem. Thanks, Guido |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by ultrotter@google.com:
The text was updated successfully, but these errors were encountered: