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

Preserve type information for each object #30

Closed
gnapse opened this issue Dec 4, 2017 · 3 comments
Closed

Preserve type information for each object #30

gnapse opened this issue Dec 4, 2017 · 3 comments

Comments

@gnapse
Copy link
Contributor

gnapse commented Dec 4, 2017

@yury-dymov I've found a couple of situations where it would have been useful to still have inside the object the type information from the jsonapi. I propose including it as a special $type attribute, which is guaranteed not to interfere with normal existing attributes, given that the jsonapi spec does not allow $ as a valid character in a member name.

With this change in place build for this jsonapi object

{
  id: '1',
  type: 'items',
  attributes: { name: 'Hello World' },
}

would become this:

{
  id: '1',
  name: 'Hello World',
  $type: 'items',
}

Makes sense? I can make the change and submit a pull request.

Update: my bad, I see that there's already an option to do this. It fits me as it is, and I'll use it. But I'd argue that the use of the name type is not ideal. An object could perfectly have an attribute named type, and this option would override it. Granted, it's an edge case, but it could technically happen.

@apsavin
Copy link
Contributor

apsavin commented Dec 4, 2017

An object could perfectly have an attribute named type

No, read the spec

http://jsonapi.org/format/#document-resource-object-fields

@yury-dymov
Copy link
Owner

Don't see any action items for me with respect to @apsavin comment :)

@gnapse
Copy link
Contributor Author

gnapse commented Dec 5, 2017

Ooops sorry, my bad.

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

3 participants