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



16
17
18
# File 'lib/http/mime_type/json.rb', line 16

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

#encode(obj) ⇒ Object

Encodes object to JSON



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

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