Type reflect.Type // type of Go value it could not be assigned to
Offset int64 // error occurred after reading Offset bytes
Struct string // name of the struct type containing the field
- Field string // name of the field holding the Go value
+ Field string // the full path from root node to the field
}
func (e *UnmarshalTypeError) Error() string {
}
subv = subv.Field(i)
}
- d.errorContext.Field = f.name
+ if originalErrorContext.Field == "" {
+ d.errorContext.Field = f.name
+ } else {
+ d.errorContext.Field = originalErrorContext.Field + "." + f.name
+ }
d.errorContext.Struct = t
} else if d.disallowUnknownFields {
d.saveError(fmt.Errorf("json: unknown field %q", key))
S SS
}
+type P struct {
+ PP PP
+}
+
+type PP struct {
+ T T
+}
+
type SS string
func (*SS) UnmarshalJSON(data []byte) error {
err: &UnmarshalTypeError{
Value: "string",
Struct: "V",
- Field: "F2",
+ Field: "V.F2",
Type: reflect.TypeOf(int32(0)),
Offset: 20,
},
err: &UnmarshalTypeError{
Value: "string",
Struct: "V",
- Field: "F2",
+ Field: "V.F2",
Type: reflect.TypeOf(int32(0)),
Offset: 30,
},
ptr: new(MustNotUnmarshalText),
err: &UnmarshalTypeError{Value: "object", Type: reflect.TypeOf(&MustNotUnmarshalText{}), Offset: 1},
},
+ // #22369
+ {
+ in: `{"PP": {"T": {"Y": "bad-type"}}}`,
+ ptr: new(P),
+ err: &UnmarshalTypeError{
+ Value: "string",
+ Struct: "T",
+ Field: "PP.T.Y",
+ Type: reflect.TypeOf(int(0)),
+ Offset: 29,
+ },
+ },
}
func TestMarshal(t *testing.T) {