Skip to content

Commit

Permalink
runtime - Emit default values in marshalled JSON
Browse files Browse the repository at this point in the history
In order to make APIs more restful, require the marshaler to emit
default values. By default, it omits empty types. This causes
unexpected REST behavior by omitting all false values or zero-valued
integers.

Closes grpc-ecosystem#233
  • Loading branch information
philipithomas authored and flw-cn committed Apr 28, 2018
1 parent 3beac66 commit aa60176
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runtime/marshaler_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ var (
acceptHeader = http.CanonicalHeaderKey("Accept")
contentTypeHeader = http.CanonicalHeaderKey("Content-Type")

defaultMarshaler = &JSONPb{OrigName: true}
// defaultMarhaler controls how protobufs are marshalled to JSON. Note that
// it uses the JSONpb package, not standard JSON / annotations. To override its
// behavior, use the WithMarshalerOption:
// gwmux := runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: false}))
defaultMarshaler = &JSONPb{OrigName: true, EmitDefaults: true}
)

// MarshalerForRequest returns the inbound/outbound marshalers for this request.
Expand Down

0 comments on commit aa60176

Please sign in to comment.