aboutsummaryrefslogblamecommitdiffstats
path: root/activejob/lib/active_job/serializers/hash_with_indifferent_access_serializer.rb
blob: af3576dd573420eae874e7f11ca9303e1ee22526 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                                              
                                                   


                
                             
                                                                           



                                        

               
               
                                     

           
                 
                                                  




           
# frozen_string_literal: true

module ActiveJob
  module Serializers
    # Provides methods to serialize and deserialize `ActiveSupport::HashWithIndifferentAccess`
    # Values will be serialized by known serializers
    class HashWithIndifferentAccessSerializer < HashSerializer
      class << self
        def serialize(hash)
          result = serialize_hash(hash)
          result[key] = Serializers.serialize(true)
          result
        end

        def deserialize(hash)
          result = hash.transform_values { |v| Serializers.deserialize(v) }
          result.delete(key)
          result.with_indifferent_access
        end

        private

        def key
          WITH_INDIFFERENT_ACCESS_KEY
        end

        def klass
          ActiveSupport::HashWithIndifferentAccess
        end
      end
    end
  end
end