From 7355dcd5a6658e31ddc226278e4695e65c8e6f60 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 24 Nov 2020 15:21:36 +0300 Subject: [PATCH] expose useful jsonpb defaults Signed-off-by: Vasiliy Tolstov --- jsonpb.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/jsonpb.go b/jsonpb.go index 8c3f470..8ad4803 100644 --- a/jsonpb.go +++ b/jsonpb.go @@ -14,10 +14,26 @@ import ( ) var ( - JsonpbMarshaler = &jsonpb.MarshalOptions{} - OldJsonpbMarshaler = &oldjsonpb.Marshaler{} - JsonpbUnmarshaler = &jsonpb.UnmarshalOptions{} - OldJsonpbUnmarshaler = &oldjsonpb.Unmarshaler{} + JsonpbMarshaler = jsonpb.MarshalOptions{ + UseEnumNumbers: false, + EmitUnpopulated: false, + UseProtoNames: true, + AllowPartial: false, + } + + JsonpbUnmarshaler = jsonpb.UnmarshalOptions{ + DiscardUnknown: false, + AllowPartial: false, + } + + OldJsonpbMarshaler = oldjsonpb.Marshaler{ + OrigName: true, + EmitDefaults: false, + } + + OldJsonpbUnmarshaler = oldjsonpb.Unmarshaler{ + AllowUnknownFields: false, + } ) type jsonpbCodec struct {