yosiat / panko_serializer

High Performance JSON Serialization for ActiveRecord & Ruby Objects
https://panko.dev
MIT License
592 stars 36 forks source link

Alias declaration is ignored when method is added #135

Closed hkdnet closed 1 year ago

hkdnet commented 1 year ago

Step to reproduce

require "panko_serializer"
require "active_support"
require "active_support/core_ext"
require "active_record"

class S1 < Panko::Serializer
  aliases({ created_at: :createdAt })
end

class S2 < Panko::Serializer
  aliases({ created_at: :createdAt })

  def created_at
    "2023-04-18T09:24:41+00:00"
  end
end

result1 = S1.new.serialize({ "created_at" => "2023-04-18T09:24:41+00:00" })
result2 = S2.new.serialize({})

p result1
p result2

Expected Behavior

S2's result should have createdAt instead of created_at because it has the alias.

$ bundle exec ruby a.rb
{"createdAt"=>"2023-04-18T09:24:41+00:00"}
{"createdAt"=>"2023-04-18T09:24:41+00:00"}

Actual Behavior

created_at is used.

$ bundle exec ruby a.rb               
{"createdAt"=>"2023-04-18T09:24:41+00:00"}
{"created_at"=>"2023-04-18T09:24:41+00:00"}
rustemmukhamadiev commented 1 year ago

Looks like this issue isn't actual after https://github.com/panko-serializer/panko_serializer/pull/136

hkdnet commented 1 year ago

I forgot to close the original issue. Thanks!