JSON difference in the key format between the client and the server
- Dominant language
- Go
- Stars
- 11
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
### **Problem**
Server and client json renderers do not match. Client code (defined in `client-go`) expects json keys in snake_case, and the server code (defined in `grafeas/grafeas`) sends json keys in camelCase. Thus, server response values are ignored by the client marshaller.
### **Example**
_Field definitions:_
client-go:
`ShortDescription string 'json:"short_description,omitempty"'`
grafeas:
`ShortDescription string 'protobuf:"bytes,2,opt,name=short_description,json=shortDescription,proto3" json:"short_description,omitempty"'`
What the client receives before the values are unmarshalled:
`"name":"projects/grafeasclienttest/notes/grafeasattestation","shortDescription":"short","longDescription":"long","kind":"ATTESTATION","relatedUrl":[],"expirationTime":"0001-01-01T00:00:00Z","createTime":"2019-11-12T14:12:44.705616Z","updateTime":"2019-11-12T14:12:44.705616Z","relatedNoteNames":[],"attestationAuthority":{"hint":{"humanReadableName":"projects/grafeasclienttest/notes/grafeasattestation"}}`
The final unmarshalled object:
`Name:projects/grafeasclienttest/notes/grafeasattestation ShortDescription: LongDescription: Kind:0xc00041b0e0 RelatedUrl:[] ExpirationTime:0001-01-01 00:00:00 +0000 UTC CreateTime:0001-01-01 00:00:00 +0000 UTC UpdateTime:0001-01-01 00:00:00 +0000 UTC RelatedNoteNames:[] Vulnerability:`
### **Potential Solution**
Rename json keys in client-go models to use the camelCase, e.g. (from `model_v1beta1_note.go`):
```go
// A one sentence description of this note.
ShortDescription string `json:"shortDescription,omitempty"`
```
Contributor guide
Assessment
This issue has not been assessed yet.