Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshall heterogeneous arrays as tagged unions #18

Open
ChimeraCoder opened this issue Mar 16, 2015 · 0 comments
Open

Unmarshall heterogeneous arrays as tagged unions #18

ChimeraCoder opened this issue Mar 16, 2015 · 0 comments

Comments

@ChimeraCoder
Copy link
Owner

This is inspired by #17.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant