tendermint: Don't use `omitempty`
Types which are generated from proto files in go have JSON annotations which contain omitempty for all keys, for example:
https://github.com/tendermint/tendermint/blob/62f97a69e97262b5feb57b1c2498f0c1e0e297b3/abci/types/types.proto#L137-L145
Results in this: https://github.com/tendermint/tendermint/blob/62f97a69e97262b5feb57b1c2498f0c1e0e297b3/abci/types/types.pb.go#L1711-L1720
Which means if you just make empty ResponseInfo{} and serialize it to JSON you would get empty JSON object, or if you do not set some field that field will be omitted from resulting JSON.
On the other hand, types defined by hand in go don’t use omitempty at all, all this results in inconsistency. As some fields are in json all the time and some aren’t, it makes writing parsers of request/response types unnecessarily harder in other statically typed languages.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (7 by maintainers)
Commits related to this issue
- Remove omitempty from *pb.go - remove omitempty from *pb.go files - added command to makefile for everytime `make protoc_all` is run - open question: - Do we want to further remove omitempty from ... — committed to tendermint/tendermint by tac0turtle 5 years ago
- custom marshallers for proto types, which EmitDefaults (#3889) * Remove omitempty from *pb.go - remove omitempty from *pb.go files - added command to makefile for everytime `make protoc_all` is r... — committed to tendermint/tendermint by tac0turtle 5 years ago
Done in https://github.com/tendermint/tendermint/pull/3889
No problem!, happy for seeing response so fast 🙌
While we are at it, there is one type which I noticed in go side having no json annotations resulting in fields named
LikeThisin json probably fixing it would be good too: https://github.com/tendermint/tendermint/blob/v0.32.2/types/tx.go#L85I agree with the reasoning here, @melekes, thoughts?