diff --git a/jsonpb.go b/jsonpb.go index 7fb0653..f966b70 100644 --- a/jsonpb.go +++ b/jsonpb.go @@ -39,16 +39,17 @@ func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, erro case *codec.Frame: return m.Data, nil case proto.Message: - if nv, nerr := rutil.StructFieldByTag(m, codec.DefaultTagName, flattenTag); nerr == nil { - if nm, ok := nv.(proto.Message); ok { - m = nm - } - } options := c.opts for _, o := range opts { o(&options) } + if nv, nerr := rutil.StructFieldByTag(m, options.TagName, flattenTag); nerr == nil { + if nm, ok := nv.(proto.Message); ok { + m = nm + } + } + marshalOptions := DefaultMarshalOptions if options.Context != nil { if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok { @@ -72,17 +73,17 @@ func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) e m.Data = d return nil case proto.Message: - if nv, nerr := rutil.StructFieldByTag(m, codec.DefaultTagName, flattenTag); nerr == nil { - if nm, ok := nv.(proto.Message); ok { - m = nm - } - } - options := c.opts for _, o := range opts { o(&options) } + if nv, nerr := rutil.StructFieldByTag(m, options.TagName, flattenTag); nerr == nil { + if nm, ok := nv.(proto.Message); ok { + m = nm + } + } + unmarshalOptions := DefaultUnmarshalOptions if options.Context != nil { if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok {