App has 4 keys in a hash property called stats
: '10s', '1min', '5min', 'day'. Each are arrays of Stat objects
In order to create a stats
attribute in AppSerializer, we have to create an
intermediary Serializer with the attributes in order to re-use StatSerializer
for each of those four Stat collections, and the syntax within that Serializer
is pretty kludgy to make the association work.
Using ActiveModel::Serializer outside of ActiveRecord requires an inclusion of ActiveModel::SerializerSupport, but the documentation does not state this, so there was some head-scratching as to why it wasn't magically working on our Mongoid models.
I find instances where I have a hash attribute that I need to specify keys of the hash that I either need to write a filtered hash object or its own Serializer object. That may or may not be working-as-intended as this has some feeling of hash-driven mentality, but it surprised me.
I cannot find a way to make the serializer data be the root of the JSON response, instead of being the data in a key. For example, if instead of wanting { 'app': { 'foo': 'bar' } } I want { 'foo': 'bar' }, there does not seem to be a way for that. I can change 'app' to 'foo' by passing the :root option, but I do not see a way to cause it to be the root of the JSON response itself.
Or failing that, the ability to use the same style of method definition on an
attributes
key as thehas_(one|many)
calls. My first instinct when I ran into this wasattributes :pusher
followed bydef pusher ; ... ; end
to modify the data getting passed as an attribute, only to see it doesn't work that way.