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
Hey,
I was trying to use the lib to unmarshal a composed struct, and expected it to work like the json package and to fill the nested struct as well.
It looks like the issue is in mapStructFields that doesn't handle composed structs so it skips the nested values.
package main
import (
"fmt"
"github.com/perimeterx/marshmallow"
)
type A struct {
Foo string `json:"foo"`
Boo []int `json:"boo"`
}
type B struct {
A
}
func main() {
marshmallow.EnableCache() // this is used to boost performance, read more below
a := A{}
result, err := marshmallow.Unmarshal([]byte(`{"foo":"bar","boo":[1,2,3],"goo":12.6}`), &a)
fmt.Printf("a=%+v, result=%+v, err=%v", a, result, err)
// Output: a={Foo:bar Boo:[1 2 3]}, result=map[boo:[1 2 3] foo:bar goo:12.6], err=<nil>
b := B{}
result, err = marshmallow.Unmarshal([]byte(`{"foo":"bar","boo":[1,2,3],"goo":12.6}`), &b)
fmt.Printf("b=%+v, result=%+v, err=%v", b, result, err)
// Output: b={A:{Foo: Boo:[]}}, result=map[boo:[1 2 3] foo:bar goo:12.6], err=<nil>
}
The text was updated successfully, but these errors were encountered:
@BarakHirsch Thanks for submitting!
Sorry for the late reply, the library is still under heavy internal use but we plan to announce it next week.
We're hosting a meetup on the matter, you're more than welcome to drop by ❤️
Regarding the issue - I see you've zeroed in, care to push a fix? I'd love to get you on board on that.
If not, I'll update on the progress in the upcoming weeks to solve it. 🙏
Hey,
I was trying to use the lib to unmarshal a composed struct, and expected it to work like the json package and to fill the nested struct as well.
It looks like the issue is in mapStructFields that doesn't handle composed structs so it skips the nested values.
The text was updated successfully, but these errors were encountered: