Sha256: e3f95437ff2e73c76b2cf9a96b9e82520053d8706d15e2ea94857f39d3a09e16

Contents?: true

Size: 1.17 KB

Versions: 70

Compression:

Stored size: 1.17 KB

Contents

require 'multi_json'

module VCR
  class Cassette
    class Serializers
      # The JSON serializer. Uses `MultiJson` under the covers.
      #
      # @see Psych
      # @see Syck
      # @see YAML
      module JSON
        extend self
        extend EncodingErrorHandling

        # @private
        ENCODING_ERRORS = [MultiJson::DecodeError, ArgumentError]
        ENCODING_ERRORS << EncodingError if defined?(EncodingError)

        # The file extension to use for this serializer.
        #
        # @return [String] "json"
        def file_extension
          "json"
        end

        # Serializes the given hash using `MultiJson`.
        #
        # @param [Hash] hash the object to serialize
        # @return [String] the JSON string
        def serialize(hash)
          handle_encoding_errors do
            MultiJson.encode(hash)
          end
        end

        # Deserializes the given string using `MultiJson`.
        #
        # @param [String] string the JSON string
        # @return [Hash] the deserialized object
        def deserialize(string)
          handle_encoding_errors do
            MultiJson.decode(string)
          end
        end
      end
    end
  end
end

Version data entries

70 entries across 70 versions & 9 rubygems

Version Path
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
vcr-5.1.0 lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
vcr-5.0.0 lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
vcr-4.0.0 lib/vcr/cassette/serializers/json.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/vcr-3.0.3/lib/vcr/cassette/serializers/json.rb
vcr-3.0.3 lib/vcr/cassette/serializers/json.rb
vcr-3.0.2 lib/vcr/cassette/serializers/json.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/vcr-2.9.3/lib/vcr/cassette/serializers/json.rb
vcr-3.0.1 lib/vcr/cassette/serializers/json.rb