Skip to content

Inconsistent JSONAPI serialization when missing related serializer #1075

Open
@beauby

Description

@beauby

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.

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