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.

If you like to override its behavior back, use the WithMarshalerOption:

```go
gwmux := runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: false}))
```

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

defaultMarshaler = &JSONPb{OrigName: true}
defaultMarshaler = &JSONPb{OrigName: true, EmitDefaults: true}
)

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

0 comments on commit 0a0ab21

Please sign in to comment.