encoding/json: How can I figure out default value from json decoder #38208
Comments
You could initialize var user with values that cannot appear in the input. You'll prob get more help via golang-nuts for Q's like this. This issue tracker isn't used that way. EDIT: possible string values: |
This belongs on stackoverflow but no, pointer is the only way pretty much. |
Hi there, Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For asking questions, see:
Please ask the question on one of the above forums. (Quoted from https://golang.org/wiki/Questions) |
I am looking for some approach to work with default values from a json decoder.
What version of Go are you using (
go version
)?Example
Both examples above will have the same output (
user.LastName == ""
) but how can I figure out if one is default value from Go struct and the other it's a input from user?I need this because of some validations in business rule inside of my app. If user put the field, for example lname I make one thing but if not I make another thing.
I just write this question in gopher#api Slack channel and the workaround was to use pointer, but for me it isn't elegant. Is there some other approach for this problem?
Many tks
The text was updated successfully, but these errors were encountered: