mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
#63 fix embed struct at last
This commit is contained in:
parent
ebed7df895
commit
d7ea1acd3f
@ -203,6 +203,8 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, binding := range structDescriptor.Fields {
|
for _, binding := range structDescriptor.Fields {
|
||||||
|
binding.Encoder = &structFieldEncoder{&field, binding.Encoder, false}
|
||||||
|
binding.Decoder = &structFieldDecoder{&field, binding.Decoder}
|
||||||
anonymousBindings = append(anonymousBindings, binding)
|
anonymousBindings = append(anonymousBindings, binding)
|
||||||
}
|
}
|
||||||
} else if field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct {
|
} else if field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct {
|
||||||
|
@ -407,6 +407,25 @@ func Test_shadow_struct_field(t *testing.T) {
|
|||||||
should.Contains(output, `"max_age":20`)
|
should.Contains(output, `"max_age":20`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_embed_at_last(t *testing.T) {
|
||||||
|
type Base struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Struct struct {
|
||||||
|
Field string `json:"field"`
|
||||||
|
FieldType string `json:"field_type"`
|
||||||
|
Base
|
||||||
|
}
|
||||||
|
should := require.New(t)
|
||||||
|
s := Struct{Field: "field", FieldType: "field_type", Base: Base{"type"}}
|
||||||
|
output, err := MarshalToString(s)
|
||||||
|
should.Nil(err)
|
||||||
|
should.Contains(output, `"type":"type"`)
|
||||||
|
should.Contains(output, `"field":"field"`)
|
||||||
|
should.Contains(output, `"field_type":"field_type"`)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_decode_nested(t *testing.T) {
|
func Test_decode_nested(t *testing.T) {
|
||||||
type StructOfString struct {
|
type StructOfString struct {
|
||||||
Field1 string
|
Field1 string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user