Active Support has an #as_json definition for String (as monkey patch) that returns self (String instance). The Enumerize::Value class is inherited from String and does not have its own #as_json definition. So, when we call as_json on an Enumerize::Value instance, we get this instance instead of its String representation, which can be used as a valid JSON value.
This can be a problem, for example, when we call as_json on a Rails model record that represents this record as valid JSON, which will be used as an argument in Sidekiq.perform_async (this happens when Sidekiq.strict_args! is set).
This problem can be solved in this way:
module Enumerize
class Value
def as_json(_options = nil) = to_s
end
end
Active Support has an #as_json definition for String (as monkey patch) that returns self (String instance). The Enumerize::Value class is inherited from String and does not have its own #as_json definition. So, when we call as_json on an Enumerize::Value instance, we get this instance instead of its String representation, which can be used as a valid JSON value. This can be a problem, for example, when we call as_json on a Rails model record that represents this record as valid JSON, which will be used as an argument in
Sidekiq.perform_async
(this happens when Sidekiq.strict_args! is set). This problem can be solved in this way: