Class: EventQ::SerializationProviders::OjSerializationProvider
- Inherits:
-
Object
- Object
- EventQ::SerializationProviders::OjSerializationProvider
- Defined in:
- lib/eventq_base/serialization_providers/oj_serialization_provider.rb
Instance Method Summary collapse
- #deserialize(json) ⇒ Object
-
#initialize ⇒ OjSerializationProvider
constructor
A new instance of OjSerializationProvider.
- #serialize(object) ⇒ Object
Constructor Details
#initialize ⇒ OjSerializationProvider
Returns a new instance of OjSerializationProvider.
5 6 7 8 |
# File 'lib/eventq_base/serialization_providers/oj_serialization_provider.rb', line 5 def initialize require 'oj' @json_serializer = EventQ::SerializationProviders::JsonSerializationProvider.new end |
Instance Method Details
#deserialize(json) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/eventq_base/serialization_providers/oj_serialization_provider.rb', line 14 def deserialize(json) begin return Oj.load(json) rescue Oj::ParseError EventQ.log(:debug, "[#{self.class}] - Failed to deserialize using Oj, falling back to JsonSerializationProvider.") return @json_serializer.deserialize(json) end end |
#serialize(object) ⇒ Object
10 11 12 |
# File 'lib/eventq_base/serialization_providers/oj_serialization_provider.rb', line 10 def serialize(object) return Oj.dump(object, mode: :object) end |