Skip to content

Commit

Permalink
docs: guidelines for proto message's String() method (#13364) (#13366)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8dd708d)

Co-authored-by: likhita-809 <78951027+likhita-809@users.noreply.github.com>
  • Loading branch information
mergify[bot] and likhita-809 committed Sep 23, 2022
1 parent 72f8923 commit c351441
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ type UnpackInterfacesMessage interface {
}
```

### Custom Stringer

Using `option (gogoproto.goproto_stringer) = false;` in a proto message definition leads to unexpected behaviour, like returning wrong output or having missing fields in the output.
For that reason a proto Message's `String()` must not be customized, and the `goproto_stringer` option must be avoided.

A correct YAML output can be obtained through ProtoJSON, using the `JSONToYAML` function:

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/codec/yaml.go#L8-L20

For example:

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/x/auth/types/account.go#L139-L151

## Next {hide}

Learn about [gRPC, REST and other endpoints](./grpc_rest.md) {hide}

0 comments on commit c351441

Please sign in to comment.