I was trying the same thing - but it is not possible. JSONAPI::Resource does not have any helper to easily convert Relation object or array of records into JSONAPI::Resource instances, so you can't pass the collection like this.
serialize_to_hash expects array of JSONAPI::Resource, so you would have to do something horrible like this:
result = []
Post.all.each do |post|
result << PostResource.new(post)
end
JSONAPI::ResourceSerializer.new(PostResource).serialize_to_hash(result)
JSONAPI::Resources expects that the JSONAPI itself should be sufficient, so no implementation of methods like index should be needed - gem will handle it itself without the need for manual serialization. But it is true, that I can imagine some scenarios, where I would want to be able to mannualy serialize collection of records, so there should be some easy way to do this...unfortunately, It looks like there is no easy way for now.
UPDATE:
I had some further questions myself so I have asked the creators of the gem here: https://github.com/cerebris/jsonapi-resources/issues/460