-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property options are ignored for JSON::Hash #215
Comments
I ran into this as well. The address field on our patient model is stored as a JSON field in MySQL. Rails converts these into a Hash. # patient_representer.rb
require 'roar/decorator'
require 'roar/json'
class PatientRepresenter < Roar::Decorator
include Roar::JSON
defaults do |name, options|
{ as: name.to_s.camelize(:lower).to_sym }
end
property :id
property :first_name
...
property :address,
decorator: AddressRepresenter # address_representer.rb
require 'roar/decorator'
require 'roar/json/hash'
class AddressRepresenter < Roar::Decorator
include Roar::JSON::Hash
defaults do |name, options|
{ as: name.to_s.camelize(:lower).to_sym }
end
property :street_name
property :house_number
property :postal_code
property :city
end Representing a patient works, but the address properties are still represented in snake_case |
I am pretty sure that defaults inherit: true do
# ..
end |
I can understand that defaults are not propagated into nested representers but in my example I have a separate defaults block in Adding the |
This doesn't work:
Neither getter, filter, nor method are being called at all.
But if replace
JSON::Hash
to justJSON
(and wrap hash intoOpenStruct
) it works as expected:The text was updated successfully, but these errors were encountered: