I recently started implementing some interfaces for my structures and I was surprised to find that the default JSON encoder appears to try encoding the interfaces as if they were variables in structures. So for example if we have:
type Foo interface{
FooMe()
}
type Bar struct {
Foo
ImportantVariable string
}
The encoded JSON would look like:
{"Foo":null,"ImportantVariable":""}
Which is kind of silly, since Foo will never be anything other than null.
I think it would be useful for JSON to check if an imported variable is only an interface, not a struct or any other data structure, and ignore it completely if it is.
The text was updated successfully, but these errors were encountered:
Sorry, I meant empt interface. One way or the other, it's trying to denote there is a variable there when we only have an interface that doesn't hold any data itself.
I recently started implementing some interfaces for my structures and I was surprised to find that the default JSON encoder appears to try encoding the interfaces as if they were variables in structures. So for example if we have:
type Foo interface{
FooMe()
}
type Bar struct {
Foo
ImportantVariable string
}
The encoded JSON would look like:
{"Foo":null,"ImportantVariable":""}
Which is kind of silly, since Foo will never be anything other than null.
I think it would be useful for JSON to check if an imported variable is only an interface, not a struct or any other data structure, and ignore it completely if it is.
The text was updated successfully, but these errors were encountered: