Reflect access child


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:

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

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.