Module: LogStash::Json

Extended by:
Json
Included in:
Json
Defined in:
lib/logstash/json.rb

Defined Under Namespace

Classes: GeneratorError, ParserError

Instance Method Summary collapse

Instance Method Details

#jruby_dump(o) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/logstash/json.rb', line 40

def jruby_dump(o)
  # test for enumerable here to work around an omission in JrJackson::Json.dump to
  # also look for Java::JavaUtil::ArrayList, see TODO submit issue
  o.is_a?(Enumerable) ? JrJackson::Raw.generate(o) : JrJackson::Json.dump(o)
rescue => e
  raise LogStash::Json::GeneratorError.new(e.message)
end

#jruby_load(data, options = {}) ⇒ Object

JRuby



34
35
36
37
38
# File 'lib/logstash/json.rb', line 34

def jruby_load(data, options = {})
  options[:symbolize_keys] ? JrJackson::Raw.parse_sym(data) : JrJackson::Raw.parse_raw(data)
rescue JrJackson::ParseError => e
  raise LogStash::Json::ParserError.new(e.message)
end

#mri_dump(o) ⇒ Object



26
27
28
29
30
# File 'lib/logstash/json.rb', line 26

def mri_dump(o)
  Oj.dump(o, :mode => :compat, :use_to_json => true)
rescue => e
  raise LogStash::Json::GeneratorError.new(e.message)
end

#mri_load(data, options = {}) ⇒ Object

MRI



20
21
22
23
24
# File 'lib/logstash/json.rb', line 20

def mri_load(data, options = {})
  Oj.load(data)
rescue Oj::ParseError => e
  raise LogStash::Json::ParserError.new(e.message)
end