Hello
I’m writing a generic JSON parser that has some requirements that are not satisfied by the inbuilt deparser. I can deparse a JSON to a map and then assign the values to fields. But when I have a struct in a struct, it doesn’t work anymore.
Here is an example of what is not working:
https://play.golang.org/p/UvSl3wl9U_p
Note It’s a generic approach for a module. So I don’t know the type of the deparsed struct at compile time so I can’t typecast directly to childNode
skillian
(Sean Killian)
July 20, 2021, 11:36am
2
On line 115, you’re creating a reflect.Value
of a pointer to a reflect.Value
:
childV := reflect.ValueOf(&f)
Instead, I recommend you take the address of the field so that when you recurse into writeValuesReflected
, your call to Elem()
gets the right value:
childV := f.Addr()
1 Like
system
(system)
Closed
October 18, 2021, 11:36am
3
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.