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


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

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

#encode(obj) ⇒ Object

Encodes object to JSON


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

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