You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSONMarshalerMarshal/UnmarshalJSON methods should take proto.Message instead of interface{}. The lack of this is causing runtime errors specifically with non-pointer versions of proto types (GenesisState vs `*GenesisState).
Problem Definition
When we first started the protobuf migration, we had use cases for JSONMarshaler for types that we never intended to fully migrate to protobuf such as legacy REST requests/responses. HybridCodec was created along those lines of reasoning and all of the JSONMarshaler methods accept interface{} and do not require proto.Message.
However, proto JSON marshaling will fail for any type that does implement proto.Message. This is especially problematic with pointer types. *GenesisState does implement proto.Message but GenesisState does not and with the current JSONMarshaler this will only show up at runtime and this is problematic.
Proposal
Make JSONMarshaler methods require proto.Message. Amino JSON marshaling will still be possible but this ensures proto json marshaling doesn't unexpectedly fail at runtime.
Use *codec.LegacyAmino directly anywhere we specifically just want to use amino - these are the legacy queriers and REST endpoints. That code will need to be refactored to not use JSONMarshaler at all and just be amino only and eventually deprecated altogether.
*codec.LegacyAminoshould not implement JSONMarshaler. Its MarshalJSON* methods should still accept interface{}. Where we need to use amino we use *codec.LegacyAmino. Were we want a choice between proto and amino we use JSONMarshaler
For Admin Use
Not duplicate issue
Appropriate labels applied
Appropriate contributors tagged
Contributor assigned/self-assigned
The text was updated successfully, but these errors were encountered:
Summary
JSONMarshaler
Marshal/UnmarshalJSON
methods should takeproto.Message
instead ofinterface{}
. The lack of this is causing runtime errors specifically with non-pointer versions of proto types (GenesisState
vs `*GenesisState).Problem Definition
When we first started the protobuf migration, we had use cases for
JSONMarshaler
for types that we never intended to fully migrate to protobuf such as legacy REST requests/responses.HybridCodec
was created along those lines of reasoning and all of theJSONMarshaler
methods acceptinterface{}
and do not requireproto.Message
.However, proto JSON marshaling will fail for any type that does implement
proto.Message
. This is especially problematic with pointer types.*GenesisState
does implementproto.Message
butGenesisState
does not and with the currentJSONMarshaler
this will only show up at runtime and this is problematic.Proposal
JSONMarshaler
methods requireproto.Message
. Amino JSON marshaling will still be possible but this ensures proto json marshaling doesn't unexpectedly fail at runtime.*codec.LegacyAmino
directly anywhere we specifically just want to use amino - these are the legacy queriers and REST endpoints. That code will need to be refactored to not useJSONMarshaler
at all and just be amino only and eventually deprecated altogether.*codec.LegacyAmino
should not implementJSONMarshaler
. ItsMarshalJSON*
methods should still acceptinterface{}
. Where we need to use amino we use*codec.LegacyAmino
. Were we want a choice between proto and amino we useJSONMarshaler
For Admin Use
The text was updated successfully, but these errors were encountered: