oj_serializers
oj_serializers copied to clipboard
attribute class method doesn't work without a block
I've noticed that if you have the following:
class PostSerializer < Oj::Serializer
attribute :title
end
You get an error:
undefined local variable or method `title' for #<PostSerializer:...>
# (eval):9:in `render_as_hash'
# /Users/david/.local/share/rtx/installs/ruby/3.0.5/lib/ruby/gems/3.0.0/gems/oj_serializers-2.0.3/lib/oj_serializers/serializer.rb:209:in `one_as_hash'
# /Users/david/.local/share/rtx/installs/ruby/3.0.5/lib/ruby/gems/3.0.0/gems/oj_serializers-2.0.3/lib/oj_serializers/serializer.rb:169:in `render_as_hash'
This works fine if you have a block or you use attributes:
# works
attribute :title do
...
end
# this works too
attributes :title
- I have AMS compat on, if that makes any difference