rpcserver: instruct REST marshaler to emit default values

This change instructs the REST proxy server to overwrite its default
JSON marshaler settings. That allows us to set EmitDefaults to true
which will result in all JSON fields returned in REST responses to
be fully populated, even if their values are falsey.
This commit is contained in:
Oliver Gugger 2020-01-27 15:06:01 +01:00
parent 1dadce7cfd
commit c8b7108eeb
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -750,6 +750,17 @@ func (r *rpcServer) Start() error {
}
}
// The default JSON marshaler of the REST proxy only sets OrigName to
// true, which instructs it to use the same field names as specified in
// the proto file and not switch to camel case. What we also want is
// that the marshaler prints all values, even if they are falsey.
customMarshalerOption := proxy.WithMarshalerOption(
proxy.MIMEWildcard, &proxy.JSONPb{
OrigName: true,
EmitDefaults: true,
},
)
// Finally, start the REST proxy for our gRPC server above. We'll ensure
// we direct LND to connect to its loopback address rather than a
// wildcard to prevent certificate issues when accessing the proxy
@ -757,7 +768,7 @@ func (r *rpcServer) Start() error {
//
// TODO(roasbeef): eventually also allow the sub-servers to themselves
// have a REST proxy.
mux := proxy.NewServeMux()
mux := proxy.NewServeMux(customMarshalerOption)
err := lnrpc.RegisterLightningHandlerFromEndpoint(
context.Background(), mux, r.restProxyDest,