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

Support question: Is it possible to unmarshal into a struct? #129

Open
flimzy opened this issue Oct 10, 2022 · 1 comment
Open

Support question: Is it possible to unmarshal into a struct? #129

flimzy opened this issue Oct 10, 2022 · 1 comment

Comments

@flimzy
Copy link

flimzy commented Oct 10, 2022

My apologies if this is addressed elsewhere, but I've looked through the example code, and all past issues and PRs, and haven't found an answer to my question.

I gather that through the use of a Wrapper, it ought to be possible to unmarshal a JSON:API document into a Go struct, but how?

The unmarshal_document_test.go example uses a struct type (User{} and Article{}) to define the schema, but then when printing the result, it uses res.Get, rather than accessing an instance of the *User and/or *Article types.

Is this possible? If so, how?

Thanks.

@mfcochauxlaberge
Copy link
Owner

I don't think it's currently possible to do what you are asking here, but it probably should.

Originally, you'd use the struct to build a Type and provide it to the Schema. Since then, a feature was added to create new instances from a Type (NewFunc field).

Using that feature, I can think of a method called ToStruct (just an example) that would create a new object using whatever was used to build the type, then populate it with the correct attributes and relationships, then return that.

I will think about this.

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

2 participants