Skip to content

UnmarshalManyPayload with Links #68

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

Closed
edisonspencer opened this issue Jan 26, 2017 · 4 comments
Closed

UnmarshalManyPayload with Links #68

edisonspencer opened this issue Jan 26, 2017 · 4 comments

Comments

@edisonspencer
Copy link

Hi,

I've been trying to use the jsonapi for marshaling and unmarshaling a JSON object containing links, and I am able to marshal the JSON object (and have the links section in it), however, I am not able to unmarshal and extract the link from the JSON object.

I am unable to find any code sample, even in the tests, to see how it could be done. Is this information lost when the unmarshal is done through this library? is there any workaround which is not clear?

Thanks.

@ChrisCooney
Copy link

It's insane how this can be considered useable without the ability of deserialising a list of objects.

@aren55555
Copy link
Contributor

@edisonspencer there is currently no one liner way to unmarshal a payload of the form:

"data": [...], 
"links": {...}

However you can do something like:

payload := new(ManyPayload)
if err = json.NewDecoder(in).Decode(payload); err != nil {
	t.Fatal(err)
}

And payload.Links should contain the Links Object at the "links" top level member. See this test for a more complete example: https://github.com/google/jsonapi/blob/master/request_test.go#L553

@rberlind
Copy link

rberlind commented Nov 9, 2020

@rberlind
Copy link

rberlind commented Nov 9, 2020

Also, it would be more helpful to have a working example that demarshalled a structure that used jsonapi structure tags.

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

4 participants