Description
I'm using the JSON API adapter with ember-data and I'm having a small compatibility issue.
The new JSON API adapter currently does not transform the attribute keys in any way. I have an attribute with an underscore in my model, it will be left untouched. ember-data/jsonapi looks up attribute names with dash-separated words. This means that these two adapters cannot be used together without changing one of them.
The jsonapi spec does not specify that words must be dash-separated, but it does recommend it (#534 (comment), reference). ember-data follows this recommendation (emberjs/data#3455).
It would be nice to have a way to use the adapter in the recommended way.
Should this transformation be handled specifically by the jsonapi adapter?
Or should AMS provide a general key transformation option (this feature dropped on 0.10.x: #534)?
EDIT:
My current workaround was to define a base serializer, from which the actual serializers inherit:
class BaseSerializer < ActiveModel::Serializer
def attributes *args
Hash[super.map do |key, value|
[key.to_s.dasherize.to_sym, value]
end]
end
end