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
A number of APIs, such as Reddit and Hacker News, return heterogenous results, with a special field (kind or type) that indicates which type it actually is.
The easiest way to handle this is to have gojson provide a super-struct which is the union of all the fields it finds, and then the developer can use []SuperStruct as a target to unmarshal this endpoint. The developer will then likely want to create separate struct definitions for each typekind, which is done by simply copying the definition and removing the fields which aren't relevant to that type. Unfortunately that step can't be done automatically, but it shouldn't be too bad.
As a bonus, we could potentially add stub toFoo(), toBar() methods for each typekind found. The developer still has to create the type Foo struct definition, but this is one extra step we can eliminate.
The text was updated successfully, but these errors were encountered:
This is inspired by #17.
A number of APIs, such as Reddit and Hacker News, return heterogenous results, with a special field (
kind
ortype
) that indicates which type it actually is.The easiest way to handle this is to have
gojson
provide a super-struct which is the union of all the fields it finds, and then the developer can use []SuperStruct as a target to unmarshal this endpoint. The developer will then likely want to create separate struct definitions for each typekind, which is done by simply copying the definition and removing the fields which aren't relevant to that type. Unfortunately that step can't be done automatically, but it shouldn't be too bad.As a bonus, we could potentially add stub
toFoo()
,toBar()
methods for each typekind found. The developer still has to create thetype Foo struct
definition, but this is one extra step we can eliminate.The text was updated successfully, but these errors were encountered: