Skip to content

Unmarshal access to "meta" #82

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

Open
mitchellh opened this issue Feb 28, 2017 · 5 comments
Open

Unmarshal access to "meta" #82

mitchellh opened this issue Feb 28, 2017 · 5 comments

Comments

@mitchellh
Copy link

It'd be great to have access to an annotation type "meta" or some other way to easily access the Meta information from a JSON API document.

Currently I'm unmarshaling twice: once into OnePayload via encoding/json and again via the jsonapi unmarshal methods. It'd be wonderful to button this up.

@svperfecta
Copy link

The point of meta is to describe the response.. What's the point of submitting a request with meta to your api? If its a required field, it should be in attributes or another object? Not disagreeing, just wondering what the use-case is?

@mitchellh
Copy link
Author

My use case is actually for a response, I'd like to extract that meta result. Currently I'm unmarshaling twice to get it since the tags don't support getting it directly.

@svperfecta
Copy link

svperfecta commented Apr 12, 2017 via email

@tscott0
Copy link

tscott0 commented Nov 21, 2018

Hi there. Is there any update on this issue or the related #95 ?

My use-case requires creating a go JSON API server and client, meaning I will need to marshal and unmarshal the data. More specifically, I would like access to the "meta" for a relationship, which seems to be already supported for marshalling (see https://github.com/google/jsonapi/blob/master/node.go#L59).

My current options seem to be:

  1. Unmarshal twice, as @mitchellh has done. I believe that this would require a little work to map the data to the appropriate relationship.
  2. Unmarshal exclusively using encoding/json.

If anyone has any other potential workarounds, I'd be extremely grateful!

@nikhilatshaw
Copy link

func setDataIntoTarget(data *Data, target interface{}) error {} is missing following chunk of code which will resolve meta part of unmarshaling
if data.Meta != nil {
err = json.Unmarshal(data.Meta, castedTarget)
if err != nil {
return err
}
}

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

No branches or pull requests

5 participants