You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After reading about changes to the reflect package in the upcoming go 1.6 release, I've realized that Zoom does not handle unexported embedded structs with exported fields the same way that the encoding/json and encoding/xml packages do. For example, consider the following:
The encoding/json package will consider the fields of inner as if they are fields of Outer, producing the following JSON:
{
"A": 42,
"B": "foo"
}
This is to support the struct composition pattern (an analogue of inheritance in classical object oriented languages).
However, Zoom does not make this consideration, and treats inner as if it were any other unexported field. As a result it will not save the A and B fields of inner in the database.
If the inner struct type were exported, Zoom would save it in the database. But it would treat it as an inconvertible type and use the fallback encoding (either encoding/json or encoding/gob) instead of saving each field as a field in the Redis hash. As a result, you would not be able to run queries on the fields of inner.
Should Zoom work more similarly to the encoding/json and encoding/xml packages and consider the fields of inner as if they were top-level fields of Outer?
The text was updated successfully, but these errors were encountered:
It looks like it's more than just a bug with visibility. Even when the embedded struct is exported, zoom sees it as an opaque field. For this particular case:
Thanks @rykov. I'm not sure if you just meant for this to be a clarifying comment, but the behavior you described is something I'm aware of and it is addressed in the original issue text:
If the inner struct type were exported, Zoom would save it in the database. But it would treat it as an inconvertible type and use the fallback encoding (either encoding/json or encoding/gob) instead of saving each field as a field in the Redis hash. As a result, you would not be able to run queries on the fields of inner.
You could argue that this is not desirable and Zoom should do something to make embedded struct fields more accessible (whether they are exported or unexported). The purpose of this issue is to discuss that possibility. What do you think?
After reading about changes to the reflect package in the upcoming go 1.6 release, I've realized that Zoom does not handle unexported embedded structs with exported fields the same way that the encoding/json and encoding/xml packages do. For example, consider the following:
The encoding/json package will consider the fields of
inner
as if they are fields ofOuter
, producing the following JSON:This is to support the struct composition pattern (an analogue of inheritance in classical object oriented languages).
However, Zoom does not make this consideration, and treats
inner
as if it were any other unexported field. As a result it will not save theA
andB
fields ofinner
in the database.If the
inner
struct type were exported, Zoom would save it in the database. But it would treat it as an inconvertible type and use the fallback encoding (either encoding/json or encoding/gob) instead of saving each field as a field in the Redis hash. As a result, you would not be able to run queries on the fields ofinner
.Should Zoom work more similarly to the encoding/json and encoding/xml packages and consider the fields of
inner
as if they were top-level fields ofOuter
?The text was updated successfully, but these errors were encountered: