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

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

Overview

The JSON serializer. Uses ‘MultiJson` under the covers.

See Also:

Constant Summary collapse

ENCODING_ERRORS =
[MultiJson::DecodeError, ArgumentError]

Instance Method Summary collapse

Methods included from EncodingErrorHandling

handle_encoding_errors

Instance Method Details

#deserialize(string) ⇒ Hash

Deserializes the given string using ‘MultiJson`.

Parameters:

  • string (String)

    the JSON string

Returns:

  • (Hash)

    the deserialized object



40
41
42
43
44
# File 'lib/vcr/cassette/serializers/json.rb', line 40

def deserialize(string)
  handle_encoding_errors do
    MultiJson.decode(string)
  end
end

#file_extensionString

The file extension to use for this serializer.

Returns:

  • (String)

    “json”



22
23
24
# File 'lib/vcr/cassette/serializers/json.rb', line 22

def file_extension
  "json"
end

#serialize(hash) ⇒ String

Serializes the given hash using ‘MultiJson`.

Parameters:

  • hash (Hash)

    the object to serialize

Returns:

  • (String)

    the JSON string



30
31
32
33
34
# File 'lib/vcr/cassette/serializers/json.rb', line 30

def serialize(hash)
  handle_encoding_errors do
    MultiJson.encode(hash)
  end
end