Closed karlgarske closed 6 years ago
DecodeObject
is for top level decoding, just like Decode
.
Example:
var dec = gojay.NewDecoder(io.Reader)
dec.DecodeObject(gojay.UnmarshalerJSONObject)
In the UnmarshalJSONObject
method, use Object
or AddObject
.
Your code updated:
type Test struct {
test string
data NestedObject
}
func (t *Test) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
switch key {
case "test":
return dec.String(&t.test)
case "data":
return dec.Object(&t.data)
}
return nil
}
Please close the issue if it works as expected, thanks!
That was it. Thank you very much -- library is great. Keep up the good work!
Working with DecodeObject and UnmarshalerJSONObject interface, and I'm getting an error decoding JSON that I've validated with couple of different validators.
Using the attached issue.go and test.json, console reads, "Invalid JSON, wrong char ':' found at position 50". Using go version 1.10.3.
issue.zip