Closed giuliano-sider closed 1 year ago
The problem here, is that an interface{} value contained a number originally. You then tried to decode a string into that value. That's why it failed - it basically saw a number first, and tried to decode a number into it, and failed.
To resolve, set InterfaceReset = true
in the Handle.
var mh codec.MsgpackHandle
mh.InterfaceReset = true
See https://pkg.go.dev/github.com/ugorji/go/codec#DecodeOptions ... and I copy docs for InterfaceReset below
// InterfaceReset controls how we decode into an interface.
//
// By default, when we see a field that is an interface{...},
// or a map with interface{...} value, we will attempt decoding into the
// "contained" value.
//
// However, this prevents us from reading a string into an interface{}
// that formerly contained a number.
//
// If true, we will decode into a new "blank" value, and set that in the interface.
// If false, we will decode into whatever is contained in the interface.
InterfaceReset bool
When running the following program with github.com/ugorji/go/codec v1.2.10 ,
I get a
error. It seems that if a map has duplicate keys and their type doesn't match up, the decoder throws a mysterious looking parse error. Is this somehow expected? I don't think duplicate keys in msgpack maps are explicitly banned from the spec (https://github.com/msgpack/msgpack/blob/master/spec.md). This is the stack trace at the line where the error is generated:
It looks like the msgpack decoder wants to get an integer (Uint64?) for the value of the second "a" element in the map, but when it sees that the value is a string, it panics.