I have structs that I am populating with data from TF state. Those structs use types.X types and have tfsdk annotations. When I try to marshal those structs to JSON, all the fields are unpopulated.
type MyStruct struct {
Foo types.String `tfsdk:"foo"`
}
Within a Create function:
var state MyStruct
req.Plan.Get(&state)
// I want a JSON representation of state
enc, _ := json.Marshal(state)
// fields of enc are empty
How do I marshal MyStruct to JSON please?
EDIT: I’d like to make clear that I’d like to avoid at all cost creating a second struct that’s basically identical to the first, with a mapping function to convert between the two, followed by marshalling the second struct.