Sha256: 658f2601d9fa1f18ac2b3ac01e2c62d8a6ee5bd978aefabb368315852c7013bf

Contents?: true

Size: 480 Bytes

Versions: 11

Compression:

Stored size: 480 Bytes

Contents

require 'json'
require 'http/mime_type/adapter'

module HTTP
  module MimeType
    # JSON encode/decode MIME type adapter
    class JSON < Adapter
      # Encodes object to JSON
      def encode(obj)
        return obj.to_json if obj.respond_to?(:to_json)
        ::JSON.dump obj
      end

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

    register_adapter 'application/json', JSON
    register_alias   'application/json', :json
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
http-0.7.4 lib/http/mime_type/json.rb
http-0.6.4 lib/http/mime_type/json.rb
http-0.7.3 lib/http/mime_type/json.rb
http-0.7.2 lib/http/mime_type/json.rb
http-0.7.1 lib/http/mime_type/json.rb
http-0.7.0 lib/http/mime_type/json.rb
http-0.6.3 lib/http/mime_type/json.rb
http-0.6.2 lib/http/mime_type/json.rb
http-0.6.1 lib/http/mime_type/json.rb
http-0.6.0 lib/http/mime_type/json.rb
http-0.6.0.pre lib/http/mime_type/json.rb