stas / jsonapi.rb

Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
MIT License
262 stars 58 forks source link

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

Closed dmolesUC closed 2 years ago

dmolesUC commented 2 years ago

Expected Behavior

Actual Behavior

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

stas commented 2 years ago

Hey, thanks for the issue @dmolesUC

You're right, this needs to be updated, as we already did in https://github.com/jsonapi-serializer/jsonapi-serializer/pull/75 (probably as easy as to just call the jsonapi-serializer implementation :thinking: )

Happy to merge it if you have time to prepare a PR.

dmolesUC commented 2 years ago

@stas Will do. I had a look at calling the json-serializer implementation, but since it's inside a class_methods block it was nontrivial, so I'm just going to do it the easy way for now.