I have read this question which asks whether json.Marshal can fail on any input and based on the answers it looks like for my situation it can't fail. My situation is the following:
I have a specific struct (no nesting, no arrays, just strings, ints of various types, bools). I need to marshal it into a json. Can it ever fail?
In more specific example:
type some struct {
F1 string `json:"f1"`
F2 uint32 `json:"f2"`
F3 int64 `json:"f3"`
F4 bool `json:"f4"`
}
func doSomething(s some) (string, error) {
data, err := json.Marshal(s)
if err != nil {
return "", err
}
return string(data), nil
}
Can doSomething
ever fail? If yes, please provide an input, otherwise explain why not. Based on my current knowledge it can't.