Sha256: c8f9d90efdbb07b66b194afffc0c1e536db9f8c57f2ed2b3752502c8ac2712ba

Contents?: true

Size: 983 Bytes

Versions: 133

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

module Aws
  module Json
    module OjEngine
      # @api private
      LOAD_OPTIONS = { mode: :compat, symbol_keys: false, empty_string: false }.freeze

      # @api private
      DUMP_OPTIONS = { mode: :compat }.freeze

      class << self
        def load(json)
          Oj.load(json, LOAD_OPTIONS)
        rescue *PARSE_ERRORS => e
          raise ParseError.new(e)
        end

        def dump(value)
          Oj.dump(value, DUMP_OPTIONS)
        end

        private

        # Oj before 1.4.0 does not define Oj::ParseError and instead raises
        # SyntaxError on failure
        def detect_oj_parse_errors
          require 'oj'

          if Oj.const_defined?(:ParseError)
            [Oj::ParseError, EncodingError, JSON::ParserError]
          else
            [SyntaxError]
          end
        rescue LoadError
          nil
        end
      end

      # @api private
      PARSE_ERRORS = detect_oj_parse_errors
    end
  end
end

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
aws-sdk-core-3.177.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.176.1 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.176.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.175.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.174.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.173.1 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.173.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.172.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.171.1 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.171.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.170.1 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.170.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.169.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.168.4 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.168.3 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.168.2 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.168.1 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.168.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.167.0 lib/aws-sdk-core/json/oj_engine.rb
aws-sdk-core-3.166.0 lib/aws-sdk-core/json/oj_engine.rb