Sha256: 2a3caabef9a377d779b2d73cc22e798f87fd37b25829d29064455837f77aa1d7

Contents?: true

Size: 1.24 KB

Versions: 107

Compression:

Stored size: 1.24 KB

Contents

require 'json'
require_relative 'json/builder'
require_relative 'json/error_handler'
require_relative 'json/handler'
require_relative 'json/parser'

module Aws
  # @api private
  module Json

    class ParseError < StandardError

      def initialize(error)
        @error = error
        super(error.message)
      end

      attr_reader :error

    end

    class << self

      def load(json)
        ENGINE.load(json, *ENGINE_LOAD_OPTIONS)
      rescue ENGINE_ERROR => e
        raise ParseError.new(e)
      end

      def load_file(path)
        self.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
      end

      def dump(value)
        ENGINE.dump(value, *ENGINE_DUMP_OPTIONS)
      end

      private

      def oj_engine
        require 'oj'
        [Oj, [{mode: :compat, symbol_keys: false}], [{ mode: :compat }], oj_parse_error]
      rescue LoadError
        false
      end

      def json_engine
        [JSON, [], [], JSON::ParserError]
      end

      def oj_parse_error
        if Oj.const_defined?('ParseError')
          Oj::ParseError
        else
          SyntaxError
        end
      end

    end

    # @api private
    ENGINE, ENGINE_LOAD_OPTIONS, ENGINE_DUMP_OPTIONS, ENGINE_ERROR =
      oj_engine || json_engine

  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
aws-sdk-core-3.33.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.32.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.31.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.30.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.29.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.28.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.27.1 lib/aws-sdk-core/json.rb
aws-sdk-core-3.27.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.26.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.25.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.24.1 lib/aws-sdk-core/json.rb
aws-sdk-core-3.24.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.23.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.22.1 lib/aws-sdk-core/json.rb
aws-sdk-core-3.22.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.21.3 lib/aws-sdk-core/json.rb
aws-sdk-core-3.21.2 lib/aws-sdk-core/json.rb
aws-sdk-core-3.21.1 lib/aws-sdk-core/json.rb
aws-sdk-core-3.21.0 lib/aws-sdk-core/json.rb
aws-sdk-core-3.20.2 lib/aws-sdk-core/json.rb