-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/json: wrong type name used in UnmarshalTypeError #68941
Labels
FixPending
Issues that have a fix which has not yet been reviewed or submitted.
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Comments
Additional information about the solution. Can we insert the // An UnmarshalTypeError describes a JSON value that was
// not appropriate for a value of a specific Go type.
type UnmarshalTypeError struct {
Value string // description of JSON value - "bool", "array", "number -5"
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 // the full path from root node to the field
} |
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 20, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 20, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
Change https://go.dev/cl/606956 mentions this issue: |
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 21, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 21, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 22, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 23, 2024
Use the outermost struct as the first element of the FieldStack, so we can output the correct and complete field path. In addition, add the embeded structure to the FieldStack. Fixes golang#68941
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 27, 2024
Including embedded struct inforamtion in error message. Fixes golang#68941
At the same time, we also lose the embedded struct information. package main
import (
"encoding/json"
"fmt"
)
type Y struct {
ZField int
}
type X struct {
YField Y
}
type A struct {
IntField int
}
type B struct {
A
}
type C struct {
B
}
func ExampleUnmarshalTypeError() {
x := X{}
if err := json.Unmarshal([]byte(`{"YField": {"ZField": "hello"}}`), &x); err != nil {
fmt.Println(err)
}
c := C{}
if err := json.Unmarshal([]byte(`{"IntField": "hello"}`), &c); err != nil {
fmt.Println(err)
}
// Output:
// json: cannot unmarshal string into Go struct field Y.YField.ZField of type int
// json: cannot unmarshal string into Go struct field C.IntField of type int
} |
j2gg0s
added a commit
to j2gg0s/go
that referenced
this issue
Aug 27, 2024
Including embedded struct inforamtion in error message. Fixes golang#68941
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
FixPending
Issues that have a fix which has not yet been reviewed or submitted.
NeedsFix
The path to resolution is known, but the work has not been done.
Go version
go version go1.22.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
Error's message is
json: cannot unmarshal string into Go struct field Y.YField.ZField of type int
What did you expect to see?
Error's message should be
json: cannot unmarshal string into Go struct field X.YField.ZField of type int
If my understanding is correct, can I submit a PR to fix this issue?
The text was updated successfully, but these errors were encountered: