From c8b7108eeb8c681baaff5d62097f7a1d07da857c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 27 Jan 2020 15:06:01 +0100 Subject: [PATCH] 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. --- rpcserver.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 16e0677d..f4e13cd6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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,