Netflix / fast_jsonapi

No Longer Maintained - A lightning fast JSON:API serializer for Ruby Objects.
Apache License 2.0
5.07k stars 425 forks source link

Unexpected behavior when object belongs_to :size #459

Closed gkpacker closed 4 years ago

gkpacker commented 4 years ago

Hello!

I'm trying to serialize my product object but it responds to size, so it is treated as a collection in:

    def is_collection?(resource, force_is_collection = nil)
      return force_is_collection unless force_is_collection.nil?

      resource.respond_to?(:size) && !resource.respond_to?(:each_pair)
    end

and ends up breaking the code:

[1] pry(#<Api::V1::ProductsController>)> ProductSerializer.new(@product).serializable_hash
NoMethodError: undefined method `each' for #<Product:0x00007f8f563881b8>

It is intended to be that way?

Workaround:

ProductSerializer.new(@product, is_collection: false).serializable_hash

Thanks!

stas commented 4 years ago

This is now merged in the forked project!

gkpacker commented 4 years ago

Nice, I'll close the issue!