I have a serializer like this:
class FooSerializer < ActiveModel::Serializer
attributes :id, :name
has_many :foo_bars, serializer: BarSerializer
end
class BarSerializer < ActiveModel::Serializer
attributes :id, :acronym
end
My issue is that when instantiating the serializer and calling as_json
on it, I get the following:
$ foo = Foo.first
$ s = FooSerializer.new(foo)
$ s.as_json
$ => {
:foo => {
:id => 1,
:name => "Foo",
:foo_bars => [
{
:id => 1,
:acronym => "F1",
},
{
:id => 2,
:acronym => "F2",
},
]
}
}
But my front end API expects to receive camelcase fooBars
rather than snake case foo_bars
. How can I configure the serializer to output the foo_bars
association with the key fooBars