Class: EventQ::SerializationProviders::JRuby::OjSerializationProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_base/serialization_providers/jruby/oj_serialization_provider.rb

Instance Method Summary collapse

Constructor Details

#initializeOjSerializationProvider

Returns a new instance of OjSerializationProvider.



5
6
7
8
# File 'lib/eventq_base/serialization_providers/jruby/oj_serialization_provider.rb', line 5

def initialize
  @json_serializer = EventQ::SerializationProviders::JsonSerializationProvider.new
  @oj_serializer = Oj::Serializer.new
end

Instance Method Details

#deserialize(json) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/eventq_base/serialization_providers/jruby/oj_serialization_provider.rb', line 14

def deserialize(json)
  begin
    return @oj_serializer.load(json)
  rescue
    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/jruby/oj_serialization_provider.rb', line 10

def serialize(object)
  @oj_serializer.dump(object)
end