Forum Discussion

lloyd's avatar
lloyd
New Contributor
2 years ago

[Go] why the JSON tags everywhere

Many (almost all) struct types defined in the code generated by the swagger-codegen Go target have tags specifying how their fields should be marshaled into JSON. These are not the models being generated, these are types that are never marshaled in any way as far as I can tell. This can't be API related because there are no equivalent XML tags. 

 

Is it just that the original author pasted them in from somewhere else without realising what they are for? I don't expect Java programmers to pay much attention to this sort of feature of Go, so it's feasible I guess.

 

Here is an example that also shows some of the inconistency at play as well.

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

type APIKey struct {
	Key    string
	Prefix string
}

 

No RepliesBe the first to reply