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, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/logstash/json.rb', line 44

def jruby_dump(o, options={})
  # TODO [guyboertje] remove these comments in 5.0
  # 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)
  JrJackson::Base.generate(o, options)

rescue => e
  raise LogStash::Json::GeneratorError.new(e.message)
end

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

JRuby



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

def jruby_load(data, options = {})
  # TODO [guyboertje] remove these comments in 5.0
  # options[:symbolize_keys] ? JrJackson::Raw.parse_sym(data) : JrJackson::Raw.parse_raw(data)

  JrJackson::Ruby.parse(data, options)

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