ActiveJob::SerializationError - Unsupported argument type: Time / DateTime
<p>I am using Rails 5 and ActiveJob to process background tasks.  I am trying to pass a object serialized with <code>as_json</code> to my job but I am receiving the following errors:</p>

<pre><code>ActiveJob::SerializationError (Unsupported argument type: Time):
ActiveJob::SerializationError (Unsupported argument type: DateTime):
</code></pre>

<p>I understand that ActiveJob will not take Time/DateTime objects due to some queueing systems not handling those type.  So the object I am trying to serialize is as follows:</p>

<pre><code>card = Card.first
=&gt; #&lt;Card id: 256, title: "quis", description: "Sunt corporis error laudantium veritatis impedit r...", due_date: "2016-12-15 12:00:00", slug: "quis", created_at: "2016-11-30 17:00:01", updated_at: "2016-11-30 17:00:01", list_id: 26, position: 0, period_type: "hours", period_length: 0.0, user_id: 1&gt;
</code></pre>

<p>When I run:</p>

<pre><code>card.as_json
=&gt; {"id"=&gt;256, "title"=&gt;"quis", "description"=&gt;"Sunt corporis error laudantium veritatis impedit repellat quasi.", "due_date"=&gt;Wed, 15 Dec 2016 12:00:00 UTC +00:00, "slug"=&gt;"quis", "created_at"=&gt;Wed, 30 Nov 2016 17:00:01 UTC +00:00, "updated_at"=&gt;Wed, 30 Nov 2016 17:00:01 UTC +00:00, "list_id"=&gt;26, "position"=&gt;0, "period_type"=&gt;"hours", "period_length"=&gt;0.0, "user_id"=&gt;1}
</code></pre>

<p>The created_at, updated_at and due_date are all instances of <code>ActiveSupport::TimeWithZone</code></p>

<p>I have tried to override this by using the following code in a initializer, which I found in another SO post but it does not help:</p>

<pre><code>class ActiveSupport::TimeWithZone
    def as_json(options = {})
        strftime('%Y-%m-%d %H:%M:%S')
    end
end
</code></pre>

<p>Could anyone help with possibly have the dates as strings when <code>as_json</code> is run on the object?</p>