Permalink
Browse files

Tighten up symbolization code

  • Loading branch information...
1 parent 91971c9 commit 1ecd127b44972f08b039b14385fcd3e6f5515560 @sferik sferik committed Mar 28, 2012
Showing with 5 additions and 9 deletions.
  1. +2 −4 lib/multi_json/engines/json_common.rb
  2. +3 −5 lib/multi_json/engines/oj.rb
@@ -3,10 +3,8 @@ module Engines
module JsonCommon
def decode(string, options={})
- opts = {}
- opts[:symbolize_names] = options[:symbolize_keys]
string = string.read if string.respond_to?(:read)
- ::JSON.parse(string, opts)
+ ::JSON.parse(string, :symbolize_keys => options[:symbolize_keys])
end
def encode(object, options={})
@@ -19,7 +17,7 @@ def process_options(options={})
return options if options.empty?
opts = {}
opts.merge!(JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
- opts.merge! options
+ opts.merge!(options)
end
end
@@ -1,17 +1,15 @@
require 'oj' unless defined?(::Oj)
-::Oj.default_options = {:mode => :compat}
-
module MultiJson
module Engines
# Use the Oj library to encode/decode.
class Oj
ParseError = SyntaxError
+ ::Oj.default_options = {:mode => :compat}
+
def self.decode(string, options = {}) #:nodoc:
- opts = {}
- opts[:symbol_keys] = options[:symbolize_keys]
- ::Oj.load(string, opts)
+ ::Oj.load(string, :symbol_keys => options[:symbolize_keys])
end
def self.encode(object, options = {}) #:nodoc:

0 comments on commit 1ecd127

Please sign in to comment.