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

Inconsistent JSONAPI serialization when missing related serializer #1075

Open
beauby opened this issue Aug 23, 2015 · 6 comments
Open

Inconsistent JSONAPI serialization when missing related serializer #1075

beauby opened this issue Aug 23, 2015 · 6 comments

Comments

@beauby
Copy link
Contributor

beauby commented Aug 23, 2015

Suppose we have a Post class with has_many :comments, along with a PostSerializer. If we forget to define a CommentSerializer, rendering a Post with the JSONAPI adapter leads to the confusing following result (the comments are actually embedded in the relationship, which breaks JSONAPI spec):

{
  data: {
    type: 'posts',
    id: 1,
    attributes: { title: 'Title', body: 'Body' }
    relationships: {
      comments: {
        { 
          data: [{ id: 1, contents: 'Contents', author_id: 1, post_id: 1 },
                 { id: 2, contents: 'Contents', author_id: 2, post_id: 1 }]
        }
      }
    }
  }
}

It might be helpful to either have a way to warn the user that a given model does not have a corresponding serializer defined (as suggested in #1068), or have a default behavior of serializing stuff as Resource Identifiers.

@joaomdmoura
Copy link
Member

Check #1068 (comment)

@beauby
Copy link
Contributor Author

beauby commented Sep 22, 2015

After giving more thoughts to this, I really think there should at least be a warning when a related serializer does not exist, because in the current situation gets very confusing when you misspel a serializer name in its definition (like class PotsSerializer).

@remear
Copy link
Member

remear commented Mar 17, 2016

@beauby This is still an issue, yes?

@beauby
Copy link
Contributor Author

beauby commented Apr 18, 2016

@remear Yes, I believe so.

@beauby
Copy link
Contributor Author

beauby commented Oct 20, 2016

This was never fixed, was it?

@NullVoxPopuli
Copy link
Contributor

Related: #1949 ?

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

4 participants