Module: VCR::Cassette::Serializers::JSON

Extended by:
EncodingErrorHandling, JSON, VCR::Cassette::SyntaxErrorHandling
Included in:
JSON
Defined in:
lib/vcr/cassette/serializers/json.rb

Overview

The JSON serializer.

See Also:

Constant Summary collapse

ENCODING_ERRORS =
[ArgumentError]
SYNTAX_ERRORS =
[::JSON::ParserError]

Instance Method Summary collapse

Methods included from EncodingErrorHandling

handle_encoding_errors

Methods included from VCR::Cassette::SyntaxErrorHandling

handle_syntax_errors

Instance Method Details

#deserialize(string) ⇒ Hash

Deserializes the given string using ‘JSON`.

Parameters:

  • string (String)

    the JSON string

Returns:

  • (Hash)

    the deserialized object



44
45
46
47
48
49
50
# File 'lib/vcr/cassette/serializers/json.rb', line 44

def deserialize(string)
  handle_encoding_errors do
    handle_syntax_errors do
      ::JSON.parse(string)
    end
  end
end

#file_extensionString

The file extension to use for this serializer.

Returns:

  • (String)

    “json”



26
27
28
# File 'lib/vcr/cassette/serializers/json.rb', line 26

def file_extension
  "json"
end

#serialize(hash) ⇒ String

Serializes the given hash using ‘JSON`.

Parameters:

  • hash (Hash)

    the object to serialize

Returns:

  • (String)

    the JSON string



34
35
36
37
38
# File 'lib/vcr/cassette/serializers/json.rb', line 34

def serialize(hash)
  handle_encoding_errors do
    ::JSON.pretty_generate(hash)
  end
end