Skip to content

Commit

Permalink
Merge pull request rails#50122 from octokatherine/job-arg-string-subc…
Browse files Browse the repository at this point in the history
…lass-serialize

Restore ActiveJob serialization for String subclasses without custom serializers
  • Loading branch information
jhawthorn authored Nov 20, 2023
2 parents 5d0ab55 + e57e462 commit 3d2e960
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion activejob/lib/active_job/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def serialize_argument(argument)
if argument.class == String
argument
else
Serializers.serialize(argument)
begin
Serializers.serialize(argument)
rescue SerializationError
argument
end
end
when GlobalID::Identification
convert_to_global_id_hash(argument)
Expand Down
11 changes: 11 additions & 0 deletions activejob/test/cases/argument_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def klass
end
end

class StringWithoutSerializer < String
end

setup do
@person = Person.find("5")
end
Expand Down Expand Up @@ -156,6 +159,14 @@ def klass
ActiveJob::Serializers._additional_serializers = original_serializers
end

test "serialize a String subclass object without a serializer" do
string_without_serializer = StringWithoutSerializer.new("foo")
serialized = ActiveJob::Arguments.serialize([string_without_serializer])
deserialized = ActiveJob::Arguments.deserialize(JSON.load(JSON.dump(serialized))).first
assert_instance_of String, deserialized
assert_equal string_without_serializer, deserialized
end

test "serialize a hash" do
symbol_key = { a: 1 }
string_key = { "a" => 1 }
Expand Down

0 comments on commit 3d2e960

Please sign in to comment.