@@ -127,7 +127,7 @@ type UnmarshalTypeError struct {
127127 Type reflect.Type // type of Go value it could not be assigned to
128128 Offset int64 // error occurred after reading Offset bytes
129129 Struct string // name of the struct type containing the field
130- Field string // the full path from root node to the field
130+ Field string // the full path from root node to the field, include embedded struct
131131}
132132
133133func (e * UnmarshalTypeError ) Error () string {
@@ -701,7 +701,10 @@ func (d *decodeState) object(v reflect.Value) error {
701701 if f != nil {
702702 subv = v
703703 destring = f .quoted
704- for _ , i := range f .index {
704+ if d .errorContext == nil {
705+ d .errorContext = new (errorContext )
706+ }
707+ for i , ind := range f .index {
705708 if subv .Kind () == reflect .Pointer {
706709 if subv .IsNil () {
707710 // If a struct embeds a pointer to an unexported type,
@@ -721,13 +724,16 @@ func (d *decodeState) object(v reflect.Value) error {
721724 }
722725 subv = subv .Elem ()
723726 }
724- subv = subv .Field (i )
725- }
726- if d .errorContext == nil {
727- d .errorContext = new (errorContext )
727+ if i < len (f .index )- 1 {
728+ d .errorContext .FieldStack = append (
729+ d .errorContext .FieldStack ,
730+ subv .Type ().Field (ind ).Name ,
731+ )
732+ }
733+ subv = subv .Field (ind )
728734 }
729- d .errorContext .FieldStack = append (d .errorContext .FieldStack , f .name )
730735 d .errorContext .Struct = t
736+ d .errorContext .FieldStack = append (d .errorContext .FieldStack , f .name )
731737 } else if d .disallowUnknownFields {
732738 d .saveError (fmt .Errorf ("json: unknown field %q" , key ))
733739 }
0 commit comments