Sha256: 19f8091d33571ad8b3f5e401af3f8289276a50ba6e873146b3d84e0e3435805d

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

framework 'Foundation'
require 'multi_json/engines/ok_json'

module MultiJson
  module Engines
    class Nsjsonserialization < MultiJson::Engines::OkJson
      ParseError = ::MultiJson::OkJson::Error
      
      def self.decode(string, options = {})
        string = string.read if string.respond_to?(:read)
        data = string.dataUsingEncoding(NSUTF8StringEncoding)
        object = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, error: nil)
        if object
          object = symbolize_keys(object) if options[:symbolize_keys]
          object
        else
          super(string, options = {})
        end
      end

      def self.encode(object, options = {})
        pretty = options[:pretty] ? NSJSONWritingPrettyPrinted : 0
        object = object.as_json if object.respond_to?(:as_json)
        if NSJSONSerialization.isValidJSONObject(object)
          data = NSJSONSerialization.dataWithJSONObject(object, options: pretty, error: nil)
          NSMutableString.alloc.initWithData(data, encoding: NSUTF8StringEncoding)
        else
          super(object, options)
        end
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
challah-0.6.2 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.6.1 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.6.0 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.5.4 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.5.3 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.5.2 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
challah-0.5.1 vendor/bundle/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/multi_json-1.1.0/lib/multi_json/engines/nsjsonserialization.rb
multi_json-1.1.0 lib/multi_json/engines/nsjsonserialization.rb