@@ -31,8 +31,44 @@ module Arguments
3131 # serialized without mutation are returned as-is. Arrays/Hashes are
3232 # serialized element by element. All other types are serialized using
3333 # GlobalID.
34- def serialize ( arguments )
35- arguments . map { |argument | serialize_argument ( argument ) }
34+ def serialize ( argument )
35+ case argument
36+ when nil , true , false , Integer , Float # Types that can hardly be subclassed
37+ argument
38+ when String
39+ if argument . class == String
40+ argument
41+ else
42+ begin
43+ Serializers . serialize ( argument )
44+ rescue SerializationError
45+ argument
46+ end
47+ end
48+ when Symbol
49+ { OBJECT_SERIALIZER_KEY => "ActiveJob::Serializers::SymbolSerializer" , "value" => argument . name }
50+ when GlobalID ::Identification
51+ convert_to_global_id_hash ( argument )
52+ when Array
53+ argument . map { |arg | serialize ( arg ) }
54+ when ActiveSupport ::HashWithIndifferentAccess
55+ serialize_indifferent_hash ( argument )
56+ when Hash
57+ symbol_keys = argument . keys
58+ symbol_keys . select! { |k | k . is_a? ( Symbol ) }
59+ symbol_keys . map! ( &:name )
60+
61+ aj_hash_key = if Hash . ruby2_keywords_hash? ( argument )
62+ RUBY2_KEYWORDS_KEY
63+ else
64+ SYMBOL_KEYS_KEY
65+ end
66+ result = serialize_hash ( argument )
67+ result [ aj_hash_key ] = symbol_keys
68+ result
69+ else
70+ Serializers . serialize ( argument )
71+ end
3672 end
3773
3874 # Deserializes a set of arguments. Intrinsic types that can safely be
@@ -68,48 +104,6 @@ def deserialize(arguments)
68104 private_constant :RESERVED_KEYS , :GLOBALID_KEY ,
69105 :SYMBOL_KEYS_KEY , :RUBY2_KEYWORDS_KEY , :WITH_INDIFFERENT_ACCESS_KEY
70106
71- def serialize_argument ( argument )
72- case argument
73- when nil , true , false , Integer , Float # Types that can hardly be subclassed
74- argument
75- when String
76- if argument . class == String
77- argument
78- else
79- begin
80- Serializers . serialize ( argument )
81- rescue SerializationError
82- argument
83- end
84- end
85- when GlobalID ::Identification
86- convert_to_global_id_hash ( argument )
87- when Array
88- argument . map { |arg | serialize_argument ( arg ) }
89- when ActiveSupport ::HashWithIndifferentAccess
90- serialize_indifferent_hash ( argument )
91- when Hash
92- symbol_keys = argument . keys
93- symbol_keys . select! { |k | k . is_a? ( Symbol ) }
94- symbol_keys . map! ( &:name )
95-
96- aj_hash_key = if Hash . ruby2_keywords_hash? ( argument )
97- RUBY2_KEYWORDS_KEY
98- else
99- SYMBOL_KEYS_KEY
100- end
101- result = serialize_hash ( argument )
102- result [ aj_hash_key ] = symbol_keys
103- result
104- else
105- if argument . respond_to? ( :permitted? ) && argument . respond_to? ( :to_h )
106- serialize_indifferent_hash ( argument . to_h )
107- else
108- Serializers . serialize ( argument )
109- end
110- end
111- end
112-
113107 def deserialize_argument ( argument )
114108 case argument
115109 when nil , true , false , String , Integer , Float
@@ -143,7 +137,7 @@ def custom_serialized?(hash)
143137
144138 def serialize_hash ( argument )
145139 argument . each_with_object ( { } ) do |( key , value ) , hash |
146- hash [ serialize_hash_key ( key ) ] = serialize_argument ( value )
140+ hash [ serialize_hash_key ( key ) ] = serialize ( value )
147141 end
148142 end
149143
0 commit comments