From 55bfa66feeb56d0cd67a93874c3317cf41969a86 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Fri, 23 Sep 2022 00:18:07 +0530 Subject: [PATCH] docs: guidelines for proto message's String() method (#13364) (cherry picked from commit 8dd708d9cc20ec38cbf85f77b410f67930c65c62) --- docs/core/encoding.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/core/encoding.md b/docs/core/encoding.md index 968640145b79..298ce752401c 100644 --- a/docs/core/encoding.md +++ b/docs/core/encoding.md @@ -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}