fix codec.Frame in case of flatten struct tag

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-09-24 00:00:41 +03:00
parent 0249d6a441
commit 4615b86fb5
2 changed files with 41 additions and 9 deletions

18
json.go
View File

@@ -43,10 +43,6 @@ func (c *jsonCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
return nil, nil
}
if m, ok := v.(*codec.Frame); ok {
return m.Data, nil
}
options := c.opts
for _, o := range opts {
o(&options)
@@ -56,6 +52,10 @@ func (c *jsonCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
v = nv
}
if m, ok := v.(*codec.Frame); ok {
return m.Data, nil
}
marshalOptions := DefaultMarshalOptions
if options.Context != nil {
if f, ok := options.Context.Value(marshalOptionsKey{}).(JsonMarshalOptions); ok {
@@ -80,11 +80,6 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
return nil
}
if m, ok := v.(*codec.Frame); ok {
m.Data = b
return nil
}
options := c.opts
for _, o := range opts {
o(&options)
@@ -94,6 +89,11 @@ func (c *jsonCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) err
v = nv
}
if m, ok := v.(*codec.Frame); ok {
m.Data = b
return nil
}
unmarshalOptions := DefaultUnmarshalOptions
if options.Context != nil {
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(JsonUnmarshalOptions); ok {