I have been trying to work out how to get this to work, and I am stuck.
I have an object that looks like this:
type PropSet map[string]*Prop
type Prop struct {
val reflect.Value
}
and I need to generate a JSON representation of all the key value pairs that it holds. I have been reading posts on SO talking about how to marshal more mundane types, but I have not been able to figure out how to deal with the reflect.Value type. I think I should be able to do something simple like this:
func (p Prop) MarshalJSON() ([]byte, error) {
return json.Marshal(p.val.Value().Interface())
}
... but it just isn't working. Any suggestions?
Additional note: I didn't write the data structure, but the reason that I think it is using the reflect.Value for the map value is that the values that we are expecting can be ints, floats, strings etc. So this is essentially needs to do some sort of type inference with base interface to figure out the return result.