Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Unmarshal access to "meta" #82

Open

Description

@mitchellh

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.

Activity

  1. svperfecta commented on Apr 11, 2017

    @svperfecta

    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?

  2. mitchellh commented on Apr 11, 2017

    @mitchellh
    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.

  3. svperfecta commented on Apr 12, 2017

    @svperfecta
  4. tscott0 commented on Nov 21, 2018

    @tscott0

    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!

  5. nikhilatshaw commented on Dec 29, 2020

    @nikhilatshaw

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions