Module: LogStash::Json
Defined Under Namespace
Classes: GeneratorError, ParserError
Instance Method Summary collapse
- #jruby_dump(o) ⇒ Object
-
#jruby_load(data, options = {}) ⇒ Object
JRuby.
- #mri_dump(o) ⇒ Object
-
#mri_load(data, options = {}) ⇒ Object
MRI.
Instance Method Details
#jruby_dump(o) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/logstash/json.rb', line 44 def jruby_dump(o) # 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, {}) rescue => e raise LogStash::Json::GeneratorError.new(e.) 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, = {}) # 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, ) rescue JrJackson::ParseError => e raise LogStash::Json::ParserError.new(e.) 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.) end |
#mri_load(data, options = {}) ⇒ Object
MRI
20 21 22 23 24 |
# File 'lib/logstash/json.rb', line 20 def mri_load(data, = {}) Oj.load(data) rescue Oj::ParseError => e raise LogStash::Json::ParserError.new(e.) end |