rails-api/active_model_serializers — pull request #393 by headcanon (2013-10-05 17:51:14+00:00)
Title: merge meta object into the root hash when options[:meta_key] is explicitly false

My needs require that the meta info for my serialized array be put into the root hash instead of in a separate "meta" object. I felt the most elegant way to do this was to check if the :meta_key option is explicitly false (as opposed to simply nil), and if that is the case, to merge the meta object into the parent.

However, doing so presents a potential issue if and when there is a naming conflict between the meta info and the serialized object. I saw three options for dealing with that:

1. override the meta value with the serialized object
2. override the serialized object with the meta value
3. change the name of either key so that there is not a conflict

2) is right out, as it would defeat the purpose of serialization at all, and the object is arguably more important than the metadata. I felt 3) would be confusing at best, and then we would have to add an extra option to specify what you would want to rename the conflicting key to, thus adding unnecessary complexity. Thus, I chose to implement option 1) in this pull request.

I also decided to override the key silently, but if the community feels throwing a warning or error is in the books, thats fine.

I am open to suggestions!