Skip to content

JSONAPI::Rails.is_collection? confused by 'size' attribute #75

@dmolesUC

Description

@dmolesUC

Expected Behavior

  • Single model instance with size attribute is recognized as not a collection

Actual Behavior

  • Single model instance with size attribute mistakenly believed to be a collection
    due to this heuristic in JSONAPI::Rails.is_collection?
  • Serialization fails with NoMethodError when attempting to call any? here in JSONAPI::Rails.add_renderer!

Steps to Reproduce the Problem

  1. Create a model with an attribute size of type string.
  2. Try to serialize it, e.g. with render jsonapi: @the_instance in a controller method.

Possible solutions

Consider using resource.is_a?(Enumerable) instead of respond_to?(:any?). This seems to be what jsonapi-serializer does now after first realizing size was a problem and trying each instead, then deciding that was more trouble than it was worth.

Specifications

  • Version: 1.7.0
  • Ruby version: 3.0.3
  • jsonapi-serializer version: 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions