You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My service parses JSON data from multiple 3rd party websites and they all provide json differently.. some of them use numbers, some use strings.. after receiving json I do several manipulations with it and then pass it to other service.. but it in cases when site returns invalid number - my json becomes invalid too which shouldn't happen by design.. json.Number value in this case should contain 0, right?
The text was updated successfully, but these errors were encountered:
Please don't ignore error return values, especially in bug reports. That's not the problem here, but people may not believe the bug report as much if you throw away errors.
Thank you Brad,
I think it's hard to solve the problem without breaking backward compatibility.. for current apps solution could be to use interface{} instead of json.Number and then do conversion manually or reassign json.Number value to a new one right after Unmarshalling.
That type Number string makes things very difficult.
I can think of an option for json.Decoder which would accept callback to validate json.Number or an option which would provide a regex to validate it.
This would help with Unmarshalling.
As about your example - I think json.Number should be defined as a struct/interface and assigning to a Number would be possible only by creating a new struct. Automatic Number <-> String should never happen.
See this discussion: https://groups.google.com/forum/#!topic/golang-nuts/EErMkG2NWIM
Playground example: http://play.golang.org/p/9ngj404GyR
My service parses JSON data from multiple 3rd party websites and they all provide json differently.. some of them use numbers, some use strings.. after receiving json I do several manipulations with it and then pass it to other service.. but it in cases when site returns invalid number - my json becomes invalid too which shouldn't happen by design.. json.Number value in this case should contain 0, right?
The text was updated successfully, but these errors were encountered: