Closed felixwatts closed 1 year ago
Alba currently does not support this kind of feature. You can use to_h
to generate a Hash and manually combine them.
I've come up with the new API below:
class FooResource
# Resource for Foo
end
class BarResource
# Resource for Bar
end
Alba.serialize([foo, bar], each_resource: true) # => Use FooResource and BarResource
The new each_resource
option makes Alba.serialize
infers resource class for each object. This would be a slow API but might be good fit for your use case. What do you think?
Yea that seems to make sense. I've personally got a workaround working using a single resource type for both actual types, but this would definitely be cleaner.
@felixwatts I'm interested in how you workaround this problem, could you share the code?
I'm closing this issue since there's some workaround. I feel I can implement it when finding a high demand of this feature, so feel free to add some comments if you want this feature.
Is your feature request related to a problem? Please describe.
I need to implement an API that returns a single JSON list containing items of multiple types.
If heterogenous lists are already supported I can't find any documentation on how to use that feature.
Describe the solution you'd like
Describe alternatives you've considered
Additional context