Class: HTTP::MimeType::JSON

Inherits:
Adapter
  • Object
show all
Defined in:
lib/http/mime_type/json.rb

Overview

JSON encode/decode MIME type adapter

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object

Decodes JSON



18
19
20
# File 'lib/http/mime_type/json.rb', line 18

def decode(str)
  ::JSON.parse str
end

#encode(obj) ⇒ Object

Encodes object to JSON



11
12
13
14
15
# File 'lib/http/mime_type/json.rb', line 11

def encode(obj)
  return obj.to_json if obj.respond_to?(:to_json)

  ::JSON.dump obj
end