I'd like to manually serialize a collection for testing purposes. I tried this:
JSONAPI::ResourceSerializer.new(PostResource).
serialize_to_hash(PostResource.new(Post.all))
This doesn't work. It appears you can only serialize a single resource here. How would one return a serialized collection of all posts?
Another way to manually serialize data, based on JSONAPI Resources features, is by using the jsonapi-utils gem:
With the
jsonapi_serialize
method:Or the high-level
jsonapi_render
method:Hope it's useful for you :-)