module ActiveSupport::Messages::SerializerWithFallback
def self.[](format)
:nodoc:
def self.[](format) if format.to_s.include?("message_pack") && !defined?(ActiveSupport::MessagePack) require "active_support/message_pack" end SERIALIZERS.fetch(format) end
def detect_format(dumped)
def detect_format(dumped) case when MessagePackWithFallback.dumped?(dumped) :message_pack when MarshalWithFallback.dumped?(dumped) :marshal when JsonWithFallback.dumped?(dumped) :json end end
def fallback?(format)
def fallback?(format) format != :marshal end
def load(dumped)
def load(dumped) format = detect_format(dumped) if format == self.format _load(dumped) elsif format && fallback?(format) payload = { serializer: SERIALIZERS.key(self), fallback: format, serialized: dumped } ActiveSupport::Notifications.instrument("message_serializer_fallback.active_support", payload) do payload[:deserialized] = SERIALIZERS[format]._load(dumped) end else raise "Unsupported serialization format" end end