Sha256: cc9564a5f414e2c7716af56d2409e9cba4ce44bdb489b9a0883b447237d3760f

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'json'

module VCR
  class Cassette
    class Serializers
      # The JSON serializer.
      #
      # @see Psych
      # @see Syck
      # @see YAML
      module JSON
        extend self
        extend EncodingErrorHandling
        extend SyntaxErrorHandling

        # @private
        ENCODING_ERRORS = [ArgumentError]
        ENCODING_ERRORS << ::JSON::GeneratorError

        # @private
        SYNTAX_ERRORS = [::JSON::ParserError]

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

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

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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
vcr-6.3.1 lib/vcr/cassette/serializers/json.rb
vcr-6.3.0 lib/vcr/cassette/serializers/json.rb
vcr-6.2.0 lib/vcr/cassette/serializers/json.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/vcr-6.1.0/lib/vcr/cassette/serializers/json.rb
vcr-6.1.0 lib/vcr/cassette/serializers/json.rb