-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Labels
Description
If I'm using grape-entity in Rails, and I do something like this:
module Entities
class User < Grape::Entity
root :users, :user
expose :id
expose :name
end
end
and then I do something like this:
Entities::User.represent(user).as_json
I'll end up with something like this:
{ "user" => { :id => 1234, :name => "Danny Boy" } }
Notice that the keys are a mixture of symbols and strings. This is because the result of Entities::User.represent(user)
is a Hash, and I think the as_json
method there actually comes from ActiveModel, which uses strings for the keys. But the value for the "user" key is a Grape::Entity, and Grape::Entity#as_json
uses symbols for the keys.
I think it would be good to have better control over the Hash that results from using a root element. Maybe create a subclass of Hash that implements as_json
and any other relevant/useful methods?
Thoughts?