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

Missing top level data field during serialization? #41

Open
v-ken opened this issue May 30, 2016 · 4 comments
Open

Missing top level data field during serialization? #41

v-ken opened this issue May 30, 2016 · 4 comments

Comments

@v-ken
Copy link

v-ken commented May 30, 2016

Hi, Thank for this library. Just not sure if I'm serializing correctly as I'm missing the top level data field as required by JSON API spec 1.0.

let dict = JSONAPIResourceParser.dictionaryFor(object)
@joshdholtz
Copy link
Owner

@v-ken Thanks for using the library 😊 Are you able to provide me with a sample object of what you are trying to parse? Easier to help with examples 😉

@v-ken
Copy link
Author

v-ken commented Jun 1, 2016

@joshdholtz Thanks for the quick response.

Looking at the current test case, the serialized dictionary has type and attributes at the top level but according to the spec,

A document MUST contain at least one of the following top-level members:

  • data: the document’s “primary data”
  • errors: an array of error objects
  • meta: a meta object that contains non-standard meta-information.

So, it should be

{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      // ... this article's attributes
    },
    "relationships": {
      // ... this article's relationships
    }
  }
}

instead of,

{
    "type": "articles",
    "id": "1",
    "attributes": {
      // ... this article's attributes
    },
    "relationships": {
      // ... this article's relationships
    }
}

Not a huge issue as we can just wrap the dictionary in another data level. Just wondering if this was intended?

@joshdholtz
Copy link
Owner

@v-ken I personally did not write the serializer part of this library (somebody else kindly wrote it for me) so I'm not actually sure if it was intended or not 😇 but I think the intention of this was to only output the serialized object itself (leaving out the data wrapper). The dictionaryForObject method only outputs the dictionary for the object and not the whole request.

We probably could/should add a helper to add that data for you though. I'm resisting to add the data into this call because that would be a pretty nice breaking change but we could create a new call with another parameter added on that adds the data around that object. It would look something like

let dict = JSONAPIResourceParser.dictionaryFor(object, wrapInData: true)

Thoughts?

@v-ken
Copy link
Author

v-ken commented Jun 16, 2016

@joshdholtz Looks good!

Not urgent though, as manually wrapping it ourselves is really not that much of an issue. Just thought it might have been unintentional rather than intended.

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