Skip to content

attribute class method doesn't work without a block #13

@dgmora

Description

@dgmora

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions