All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.multi_json-1.12.1.lib.multi_json.adapters.ok_json.rb Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
require 'multi_json/adapter'
require 'multi_json/convertible_hash_keys'
require 'multi_json/vendor/okjson'

module MultiJson
  module Adapters
    class OkJson < Adapter
      include ConvertibleHashKeys
      ParseError = ::MultiJson::OkJson::Error

      def load(string, options = {})
        result = ::MultiJson::OkJson.decode("[#{string}]").first
        options[:symbolize_keys] ? symbolize_keys(result) : result
      rescue ArgumentError # invalid byte sequence in UTF-8
        raise ParseError
      end

      def dump(object, _ = {})
        ::MultiJson::OkJson.valenc(stringify_keys(object))
      end
    end
  end
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy