You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am migrating from gopkg.in/yaml.v2 to github.com/goccy/go-yaml and I've found an odd difference in behavior:
inFile, err := os.Open("config_goccy.yml")
if err != nil {
log.Fatalf("Can't open config_goccy.yml: %v", err)
}
defer inFile.Close()
var roundTrippedConfig AppConfig
decoder := gyaml.NewDecoder(inFile)
if err := decoder.Decode(&roundTrippedConfig); err != nil {
log.Fatalf("Unable to unmarshal data from config_goccy.yml: %v", err)
}
log.Printf("Decoded from config_goccy.yml: %+v", roundTrippedConfig)
This code works as written. However if I change "var roundTrippedConfig AppConfig" to "var roundTrippedConfig *AppConfig" then after decoder.Decode runs the value of *AppConfig is nil - this also differs from the behavior of encoding/json. This only seems to be an issue with the top most structure - I have a number of sub types that are pointers to structures or pointers to arrays of pointers.
I tried adding a "roundTrippedConfig = new(AppConfig)" before the decoder.Decode and that generated more errors, but if I change &roundTrippedConfig to roundTrippedConfig in that case it does work. So the issue seems to be if decode.Decoder is passed a pointer to a pointer (**AppConfig). So I see what the workaround is but if go-yaml accepts a double pointer then it would be a drop-in replacement.
The text was updated successfully, but these errors were encountered:
I am migrating from gopkg.in/yaml.v2 to github.com/goccy/go-yaml and I've found an odd difference in behavior:
This code works as written. However if I change "var roundTrippedConfig AppConfig" to "var roundTrippedConfig *AppConfig" then after decoder.Decode runs the value of *AppConfig is nil - this also differs from the behavior of encoding/json. This only seems to be an issue with the top most structure - I have a number of sub types that are pointers to structures or pointers to arrays of pointers.
I tried adding a "roundTrippedConfig = new(AppConfig)" before the decoder.Decode and that generated more errors, but if I change &roundTrippedConfig to roundTrippedConfig in that case it does work. So the issue seems to be if decode.Decoder is passed a pointer to a pointer (**AppConfig). So I see what the workaround is but if go-yaml accepts a double pointer then it would be a drop-in replacement.
The text was updated successfully, but these errors were encountered: